Filter löschen
Filter löschen

storing The for loop data

2 Ansichten (letzte 30 Tage)
Prasad Joshi
Prasad Joshi am 9 Feb. 2022
Kommentiert: Prasad Joshi am 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

Akzeptierte Antwort

KSSV
KSSV am 9 Feb. 2022
Bearbeitet: KSSV am 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 Kommentare
Prasad Joshi
Prasad Joshi am 9 Feb. 2022
Thank you sir ...for more information ...
Prasad Joshi
Prasad Joshi am 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 ..

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by