Save data in a double for loop with different dimensions
Afficher commentaires plus anciens
Dear all
I have a question if you can help me with. I have a program with two loops. In the first loop ( for example, matrix A), after that, I have a second loop (for example, matrix B). In the second loop, I have another caculation depend in each of A ( for example, to find C) in each A for all B. In final i want to save the matrix (C ) required in dimensions A and B.
clear all
clc
A=[0.5 1 1.5 2]
B=[2 4 6 8 10 12 15 18];
for i=1:1:length(A)
A=A(i);
for j=1:1:length(B)
C(:,j)=B(j)+A; % should save matrix C for all j in each i (should be matrx in (4*8))
end
end
2 commentaires
This is MATLAB:
A = [0.5,1,1.5,2];
B = [2,4,6,8,10,12,15,18];
C = A(:)+B
mohammed hussein
le 5 Jan 2026
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!