Unable to generate the plot
显示 更早的评论
Script:
load samples.mat
w1_x1 = zeros(1,10);
w1_x2 = zeros(1,10);
w2_x1 = zeros(1,10);
w2_x2 = zeros(1,10);
w3_x1 = zeros(1,10);
w3_x2 = zeros(1,10);
for i = 1:10
w1_x1(i) = samples(i,1);
w2_x1(i) = samples(i,4);
w3_x1(i) = samples(i,7);
w1_x2(i) = samples(i,2);
w2_x2(i) = samples(i,5);
w3_x2(i) = samples(i,8);
end
mw1x1 = mean(w1_x1);
mw1x2 = mean(w1_x2);
mw2x1 = mean(w2_x1);
mw2x2 = mean(w2_x2);
mw3x1 = mean(w3_x1);
mw3x2 = mean(w3_x2);
scatter(w1_x1,w1_x2, "red");
title("2D Plot")
xlabel("x1")
ylabel("x2")
hold on
scatter(w2_x1,w2_x2, "blue");
scatter(w3_x1,w3_x2, "green")
scatter(mw1x1,mw1x2, "red", "filled")
scatter(mw2x1,mw2x2, "blue", "filled")
scatter(mw3x1,mw3x2, "green", "filled")
hold off
Result:
Execution of script samples as a function is not supported:
/MATLAB Drive/samples.m
Error in class_exercise_taskII (line 15)
w1_x1(i) = samples(i,1);
1 个评论
dpb
2022-10-5
Just what it says -- you can't call a script m-file as if it were a function -- you would have to wrap the above inside the function and end keywords to define the function to use it in that manner and have it return the desired results.
But, it looks like you probably could just as well clean up the above code in line in the other script and put it inline there instead since it appears to do everything
load samples.mat
w1_x1= samples(:,1);
w2_x1= samples(:,4);
w3_x1= samples(:,7);
w1_x2= samples(:,2);
w2_x2= samples(:,5);
w3_x2= samples(:,8);
mw1x1 = mean(w1_x1);
mw1x2 = mean(w1_x2);
mw2x1 = mean(w2_x1);
mw2x2 = mean(w2_x2);
mw3x1 = mean(w3_x1);
mw3x2 = mean(w3_x2);
scatter(w1_x1,w1_x2, "red");
title("2D Plot")
xlabel("x1")
ylabel("x2")
hold on
scatter(w2_x1,w2_x2, "blue");
scatter(w3_x1,w3_x2, "green")
scatter(mw1x1,mw1x2, "red", "filled")
scatter(mw2x1,mw2x2, "blue", "filled")
scatter(mw3x1,mw3x2, "green", "filled")
hold off
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!