필터 지우기
필터 지우기

storing The for loop data

조회 수: 1 (최근 30일)
Prasad Joshi
Prasad Joshi 2022년 2월 9일
댓글: Prasad Joshi 2022년 2월 9일
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