Unable to generate the plot
Afficher commentaires plus anciens
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 commentaire
dpb
le 5 Oct 2022
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
Réponses (0)
Catégories
En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!