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

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에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2022년 10월 5일

댓글:

dpb
2022년 10월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by