필터 지우기
필터 지우기

How to include a variable in "xlswrite" matrix name and cell range?

조회 수: 8 (최근 30일)
Ahmad Fakih
Ahmad Fakih 2019년 10월 29일
댓글: Ahmad Fakih 2019년 10월 29일
Dear members,
I want to include variables x,x1 and x2 in the following function, where x represents the matrix and xls file names and x1 x2 represent the range overwhich the matrix will be written in excel.
xlswrite('Jx.xls',Jx,'Ax1:Bx2')
This function will be written in a "double for loop" that subtitutes x first then x1 x2 thus generating multiple excel files.
Thank you!

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 29일
Put your arrays into a single cell array Jx
filename = sprintf('J%d.xls', x);
range = sprintf('A%d:B%d', x1, x2);
xlswrite(filename, Jx{x}, range);
You might have noticed that I did not dynamically generate variable names J1 J2 and so on to write out. See http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
  댓글 수: 2
Ahmad Fakih
Ahmad Fakih 2019년 10월 29일
Thank you, works well except Jx{x} form isn't working.
Ahmad Fakih
Ahmad Fakih 2019년 10월 29일
Nevermind, figured it out and it works well. Thanks again!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by