reading excel data in for loop
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Adel Gohari
le 4 Nov 2019
Commenté : Adel Gohari
le 5 Nov 2019
Hi. I intend to assign the value of each cell of TT(x,y) inside the for loop.
A: is a 501*584 matrics including zero and non-zero values.
solid is a 501*584 matrics including 0 and 1 value (0 and 1 indicate the liquid and solid area, respectively).
Lx is the number of rows (501), and Ly is the number of columns (584).
but when the code is run, the "subscripted assignement dimension mismatch" error message related to the line number 5 was appeared. Highly appreciate any solution for this problem.
1- T = xlsread ('A');
2- for y=1:Ly
3- for x=1:Lx
4- if solid (x,y)==0
5- TT(x,y)=T;
6- else
7- TT(x,y)=0;
8- end
9- end
0 commentaires
Réponse acceptée
Walter Roberson
le 4 Nov 2019
TT(x,y) = T(x,y);
You are currently trying to assign all of T into the specific location TT(x,y)
Note: if I am corect that you want T(x,y) then your code can be made much more compact, with no for loops at all:
TT = T .* (solid == 0);
When solid is non-zero then solid==0 is false, which is 0, and 0 times anything finite is 0 is the result of the expression.
When solid is 0 then solid==0 is true, which is 1, and 1 times anything numeric is the value itself.
No loops needed.
Note: if some T values might be infinite where solid is not zero then 0*infinity is nan instead of being 0, so if that is a realistic case, you should consider
TT((solid == 0) & isnan(TT)) = 0;
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!