필터 지우기
필터 지우기

loop for excel in MATLAB

조회 수: 6 (최근 30일)
Samer Husam
Samer Husam 2012년 6월 7일
hi all, I want to save values from MATLAB to excel so I want to write a loop to check if the cell has a value or not, for example: lets consider the column (B) I want the matlab to start checking from B4 which one is empty cell to save the new values in it, how this can be done ?? looking for your help please.
  댓글 수: 2
per isakson
per isakson 2012년 6월 7일
Did you look in the Matlab on-line help?
Samer Husam
Samer Husam 2012년 6월 7일
I tried to, but couldn't find the way to do it,
actually i could write the code for the loop in order to check the value for a cell.
any suggestions please ?

댓글을 달려면 로그인하십시오.

채택된 답변

Samer Husam
Samer Husam 2012년 6월 8일
thanks all for your help, but I can't make this work cause its not really clear to me.. so, is there another way to do it ? for example: for column B in (excel) write loop program to check if the cell has value or not ?
%------a:is the variable to save------
for i=5
xlsread(('G:\\MATLAB Examples\Data_sheet.xlsx','Sheet1','B%i','value')==1;
i+1;
end
xlswrite(G:\\MATLAB Examples\Data_sheet.xlsx',a,'Sheet1','B%i,)
can something like this to be done between matlab and excel ??

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 6월 7일
one way
[nt,nt,nt] = xlsread('nameyour.xlsx');
nt(cellfun(@isnan,nt)) = {256};
xlswrite('nameyour.xlsx',nt)
ON Samer's reply
eg, data:
xlswrite('Data_sheet.xlsx',[1;8;1;6;1],'B1:B5')
solution
a = 100;
[n,t,nt] = xlsread('Data_sheet.xlsx','B1:B5');
n(n == 1) = a;
xlswrite('Data_sheet.xlsx',n,'B1:B5')
  댓글 수: 3
Image Analyst
Image Analyst 2012년 6월 8일
He's setting those Excel cells (which are now in a MATLAB cell array called nt) that are not numbers to have the new value of 256. You can change the 256 to whatever number you want. Then it writes if back out to the same file. If you want just some submatrix (like B4..F42), then you'd have to extract that submatrix before running andrei's code on just that submatrix. Then insert the submatrix back into the full matrix and write out the full matrix.
Andrei Bobrov
Andrei Bobrov 2012년 6월 8일
Thank you Image Analyst! Such a good explanation difficult for me (English is not my mother tongue).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by