matrix equation in loop form

I would like to creat a matrix, by using the loop structure, because i have a very big values, I tried this code but no result ; any help please
A=[2 2 6 6 4 4;2 2 6 6 4 4]
for n=1:length(A)
for m=1:2
if n=1:2 & m=1:2
A=2
elseif n=3:4 & m=1:2
A=6
else
A=4
end
end
end

8 comentarios

Rik
Rik el 8 de Mayo de 2022
Those if statements are probably not doing what you think they're doing, and you overwrite the value of A.
I suspect you want to index into an output matrix, but I can't tell for sure what you want to happen. Can you explain it in words?
marwa hajji
marwa hajji el 8 de Mayo de 2022
Editada: marwa hajji el 8 de Mayo de 2022
i would like to creat a matrix :
A=[2 2 6 6 4 4;2 2 6 6 4 4]
but in the structure of loop
marwa hajji
marwa hajji el 8 de Mayo de 2022
Editada: marwa hajji el 8 de Mayo de 2022
I would like display this matrix
Jan
Jan el 8 de Mayo de 2022
Editada: Jan el 8 de Mayo de 2022
What's wrong with this code:
A = [2 2 6 6 4 4; 2 2 6 6 4 4]
The code in the original question contains about 9 problems. I suggest to work through Matlab's Onramp to learn the basics: https://www.mathworks.com/learn/tutorials/matlab-onramp.html
Rik
Rik el 9 de Mayo de 2022
Why exactly do you want to create the A matrix in a loop?
Consider :
A=repmat([2 2 6 6 4 4],2,1)
A = 2×6
2 2 6 6 4 4 2 2 6 6 4 4
Maybe one of these is useful:
A = repelem([2 6 4],2,2)
A = 2×6
2 2 6 6 4 4 2 2 6 6 4 4
A = kron([1 3 2],2*ones(2))
A = 2×6
2 2 6 6 4 4 2 2 6 6 4 4
Or:
repelem([2,4,6], 2, 2)
ans = 2×6
2 2 4 4 6 6 2 2 4 4 6 6

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 8 de Mayo de 2022

Comentada:

Jan
el 11 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by