필터 지우기
필터 지우기

How can I load variable mat file with similar name, modify them and save them again?

조회 수: 2 (최근 30일)
for i=1:num
v = sprintf('Following_%d',i);
l = heigth(v)
end
*I want to read the size of the table, load a column of that specific table, find values equal to 0 and save it again. The same process with multiple tables.
  댓글 수: 1
Rik
Rik 2019년 12월 11일
So you have some variables stored in a mat file and you want to find their sizes? Why don't you load into a struct (which you should do anyway) and loop over the fields?
And avoid numbered variables. They are a bad idea if you are going to generate variable names at runtime.

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 12월 11일
filename = 'AppropriateFileNameGoesHere.mat';
ds = load(filename);
for i=1:num
fn = sprintf('Following_%d',i);
v = ds.(fn);
l = height(v);
c = v{:,appropriate_column_index};
idx = find(c == 0);
something something something
ds.(fn) = changed v;
end
save(filename, '-struct', ds)

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by