How to increment matrix row only inside a nested for loop?
Mostra commenti meno recenti
for i= 1:10{
for j= 1:5{
x = i*j;
mat
}}
matrix's row number index row wise should increment by 1
save this x value in mat matrix's row wise(like 1st row,2nd row,...,50th row).
Please help
4 Commenti
Ruger28
il 6 Nov 2019
We need more info here to help at all. This also just looks like a homework problem that you did not attempt to do.
Bob Thompson
il 6 Nov 2019
Are you adapting this code from a different program? This is not Matlab syntax.
In order to save the value from a loop into an array you need to assign the index. Something like the following:
for i = 1:10{
for j = 1:5{
x(i,j) = i*j;
mat
}}
iB
il 7 Nov 2019
iB
il 7 Nov 2019
Risposte (1)
Bob Thompson
il 7 Nov 2019
0 voti
The solution is indexing. You can do math in your index if you need to.
x((i-1)*5+j) = i*j;
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!