How to save output?

1 Ansicht (letzte 30 Tage)
Ammy
Ammy am 25 Mär. 2021
Kommentiert: Star Strider am 25 Mär. 2021
x=[0:n-1];
y=[0:n-1];
figure
for i=1:5
for j=1:5
if rem(((y(j))^2)-((x(i))^3)-2*(x(i))-3,5)==0
plot(x(i),y(j),'r o');
hold on;
end
end
end
grid;
hold off;
How can I save output of loop ? For example in this case I have 6 points (1, 1),(1, 4),(2, 0),(3, 1),(3, 4),(4, 0), how can I save it?

Akzeptierte Antwort

Star Strider
Star Strider am 25 Mär. 2021
Try this:
n = 10;
x=[0:n-1];
y=[0:n-1];
k = 0; % <- ADD
figure
for i=1:5
for j=1:5
if rem(((y(j))^2)-((x(i))^3)-2*(x(i))-3,5)==0
k = k+1; % <- ADD
xy_mtx(k,:) = [x(i) y(j)]; % <- ADD
plot(x(i),y(j),'r o');
hold on;
end
end
end
grid;
hold off
The results are saved in ‘xy_mtx’.
  2 Kommentare
Ammy
Ammy am 25 Mär. 2021
Thank you very much
Its work
Star Strider
Star Strider am 25 Mär. 2021
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by