Making a for-loop based on a condition for the third dimension of a 3D Array

2 Ansichten (letzte 30 Tage)
I would like to include "a3" as a condition in the for-loop but cant get it to work. The final form of "AllaMatriser" should be a 24x365x60 where the change from the actuall for-loop should have affact only 30 out of the 60 sheets, where the other 30 would be left unchanged.
Thanks in advanced!
AntalObjekt = 60;
Procent = 0.5;
AntalLadd = fix(AntalObjekt*Procent);
i =11;
b3 = 1:AntalObjekt;
a3 = randsample(b3, AntalLadd);
for i = i
AllaMatriser(m_spotpris==1) = i; % Both AllaMatriser and m_spotpris are 24x365x60 matrices
end

Akzeptierte Antwort

Jan
Jan am 18 Aug. 2022
Omit strange useless lines like "for i = i".
AntalObjekt = 60;
Procent = 0.5;
AntalLadd = fix(AntalObjekt*Procent);
i = 11;
a3 = randparm(AntalObjekt, AntalLadd);
match = false(size(m_spotpris));
match(:, :, a3) = (m_spotpris(:, :, a3) == 1);
AllaMatriser(match) = i;

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays 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