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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Jan
Jan le 18 Août 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;

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by