Effacer les filtres
Effacer les filtres

storing The for loop data

1 vue (au cours des 30 derniers jours)
Prasad Joshi
Prasad Joshi le 9 Fév 2022
Commenté : Prasad Joshi le 9 Fév 2022
How can I stored the for loop data ...for each loop..Its overwriting the previous data .. I am storing in C..But it is taking only last loop by overwriting previous values any inputs how can I do this ...Thank you in Adance ...any improvement in code can someone suggest
clear all
close all
clc
A=xlsread('Compare_All_cases','B1:AB37');
B=[]
for i= 1:12
B=[B;A(i,:)]
end
for i=1:3:12
effi1=(B(i,:)-B((i+1),:))./(B(i,:))*100
effi2=(B((i+1),:)-B((i+2),:))./(B((i+1),:))*100
effi3=(B(i,:)-B((i+2),:))./(B(i,:))*100
C=vertcat(effi1,effi2,effi3);
end

Réponse acceptée

KSSV
KSSV le 9 Fév 2022
Modifié(e) : KSSV le 9 Fév 2022
The below line
A=xlsread('Compare_All_cases','B1:AB37');
B=[]
for i= 1:12
B=[B;A(i,:)]
end
can be achieved by:
A=xlsread('Compare_All_cases','B1:AB37');
A = A' ;
B = A(:) ;
The rest of the lines:
for i=1:3:12
effi1=(B(i,:)-B((i+1),:))./(B(i,:))*100
effi2=(B((i+1),:)-B((i+2),:))./(B((i+1),:))*100
effi3=(B(i,:)-B((i+2),:))./(B(i,:))*100
C=vertcat(effi1,effi2,effi3);
end
can be used:
C = cell([],1) ;
count = 0;
for i=1:3:12
count = count+1 ;
effi1=(B(i,:)-B((i+1),:))./(B(i,:))*100
effi2=(B((i+1),:)-B((i+2),:))./(B((i+1),:))*100
effi3=(B(i,:)-B((i+2),:))./(B(i,:))*100
C{i}=vertcat(effi1,effi2,effi3);
end
You can convert the above cell into a amtrix. Read about Cell2mat.
  4 commentaires
Prasad Joshi
Prasad Joshi le 9 Fév 2022
Thank you sir ...for more information ...
Prasad Joshi
Prasad Joshi le 9 Fév 2022
Can you answer this also sir if possible ...if you give hint for that variable / syntax that would also be fine .. thank you in advance sir ..

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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