How to record result in a for loop nested in a for loop?

1 Ansicht (letzte 30 Tage)
Hong Sheng Lee
Hong Sheng Lee am 1 Mär. 2020
Kommentiert: Hong Sheng Lee am 1 Mär. 2020
The purpose of my code is to combine the output from multiple output which is nested in a for loop.
When i tried (as much as I know), the error "Subscripted assignment dimension mismatch" pops out.
example of the code is as follows:
for i = 1:5
for j = 1:10
matA = [j+i];
matB = [j*5 j+1];
outtemp (j,:) = [matA matB];
end
alpha = i*10;
outfinal (alpha,:) = [outtemp];
end
Thanks in advance.
PS: I tried changing the outfinal into outfinal(i,:), but the same error pops out.

Akzeptierte Antwort

Cameron B
Cameron B am 1 Mär. 2020
Not sure what the point of alpha is, but here’s something to save your data.
clc
clear
for i = 1:5
for j = 1:10
matA = [j+i];
matB = [j*5 j+1];
outtemp (j,:) = [matA matB];
end
alpha = i*10;
outfinal (:,:,i) = [outtemp];
end
  1 Kommentar
Hong Sheng Lee
Hong Sheng Lee am 1 Mär. 2020
Hi, thank you for the answer. You are a lifesaver.
Kudos for the quick response. (I thought of going home for the day but this keeps me going, thanks a lot!)

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

Produkte


Version

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by