storing The for loop data

3 次查看(过去 30 天)
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

采纳的回答

KSSV
KSSV 2022-2-9
编辑:KSSV 2022-2-9
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 个评论
Prasad Joshi
Prasad Joshi 2022-2-9
Thank you sir ...for more information ...
Prasad Joshi
Prasad Joshi 2022-2-9
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 ..

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by