How to create nested loop?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Kabit Kishore
am 4 Feb. 2022
Kommentiert: Kabit Kishore
am 4 Feb. 2022
Hi
Currently i am writing a program in MATLAB. In the program i have some indexed values that i want to use for further analysis. The indexed vales under the variable name toggle(idx.maxpts) are as follows:
ans =
1.0e-08 *
0.0844
0.1368
0.3354
0.7585
In the program i want to create a nested loop where i want to apply some equations to the first values and apply some equations to the third and fourth values and save the results. Once i have the output i want to apply some other equation to get the desired result. Thank you, any help is highy appreciated.
0 Kommentare
Akzeptierte Antwort
Voss
am 4 Feb. 2022
A demonstration of nested for loops in MATLAB:
A = magic(5);
disp(A);
[m,n] = size(A);
for ii = 1:m
for jj = 1:n
disp(A(ii,jj));
end
end
3 Kommentare
Voss
am 4 Feb. 2022
eqn = { ...
@(x)x^2 ...
@(x)x^3-2*x ...
@(x)sin(x)+exp(-x) ...
@(x)cos(x)^2-abs(x) ...
@(x)cos(x)^2+sin(x)^2 ...
};
A = magic(5);
disp(A);
[m,n] = size(A);
for ii = 1:m
for jj = 1:n
disp(eqn{ii}(A(ii,jj)));
end
end
Weitere Antworten (0)
Siehe auch
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!