how to print all of output value from "for loping" function ?

1 Ansicht (letzte 30 Tage)
ElizabethR
ElizabethR am 13 Apr. 2016
Kommentiert: ElizabethR am 14 Apr. 2016
i have a code :
function f=coba1(a);
for j=1:a
f=j;
end
.....................
a=5;
b=coba1(a);
...........................
f =1
f =2
f =3
f =4
f =5
b =5
but, the variabel b only save the last value of function loop. so, how to save all of value from this looping ? thanks

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 13 Apr. 2016
function f=coba1(a)
f = zeros(a,1);
for jj=1:a
f(jj)=jj;
end
or
f = (1:a).';

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by