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
      
      
 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
      
      
 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 个评论
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!