필터 지우기
필터 지우기

How to for loop readtable and writetable range?

조회 수: 14 (최근 30일)
Anilcan Taner
Anilcan Taner 2021년 4월 25일
댓글: Anilcan Taner 2021년 4월 26일
Let's say I have a worksheet consist of words and numbers. I want to change certain cells or cell groups with a for loop. How may I handle it?
data=readtable('test4.xls','ReadVariableNames',0,'Range','Ex:Fx');
writetable(A, 'test4.xls','WriteVariableNames',0, 'Range', 'BX:CX');
I want the "x" values here to be change as for loop goes on from i=1:10, lets say.
(To be more clear, if i = 3 the range will be E3:F3)
Btw, the solution has to in this form ( readtable and writetable) . Since I'm using Ubuntu and couldn't find any other solution for now, to my problem. Other solutions are currently either not avaible in R2018a or does not overwrites to existing .xls file.

채택된 답변

VBBV
VBBV 2021년 4월 25일
편집: VBBV 2021년 4월 25일
%f true
%if true
for i = 1:10
R1 = sprintf('%s%d:%s%d',char(069),i,char(070),i);
R2 = sprintf('%s%d:%s%d',char(066),i,char(067),i);
data=readtable('test4.xls','ReadVariableNames',0,'Range',R1);
writetable(A, 'test4.xls','WriteVariableNames',0, 'Range', R2);
end
Try this
  댓글 수: 1
Anilcan Taner
Anilcan Taner 2021년 4월 26일
I got the idea I' ve to change some few, but at the end issue is solved. However, I want to ask is there any other way to write column names other than char(xxx)? If not how may I translate A, B, C .. etc?

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

추가 답변 (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