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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Jan
Jan il 18 Ago 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;

Più risposte (0)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by