Azzera filtri
Azzera filtri

storing The for loop data

1 visualizzazione (ultimi 30 giorni)
Prasad Joshi
Prasad Joshi il 9 Feb 2022
Commentato: Prasad Joshi il 9 Feb 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

Risposta accettata

KSSV
KSSV il 9 Feb 2022
Modificato: KSSV il 9 Feb 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 Commenti
Prasad Joshi
Prasad Joshi il 9 Feb 2022
Thank you sir ...for more information ...
Prasad Joshi
Prasad Joshi il 9 Feb 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 ..

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by