Can I sort a table in regards to whether or not it contains a certain table heading?

2 ビュー (過去 30 日間)
Simeon
Simeon 2024 年 7 月 16 日
移動済み: dpb 2024 年 7 月 16 日
I currently have a code that can sort through files picking out csv files for sorting but not all the csv files contain data that needs sorting. To get around this I was hoping to implement an if loop where if table.Properties.VariableNames ==1 it will sort it otherwise it will ignore it but I can't seem to find a way to do this so was wondering if it is possible?

回答 (1 件)

dpb
dpb 2024 年 7 月 16 日
移動済み: dpb 2024 年 7 月 16 日
Show us the loop code for context...
Is the condition that there is only one variable in the files that are not to be sorted (by inference from the ==1 above)?
If you're reading the files into a table and the above is the case, then simply
for i=1:nFiles % loop over all files from a dir() or however determine
t=readtable(file(i), ...); % read each in turn
if width(t)>1 % check on number variables,
t=sortrows(t,...); % >1, sort
end
... % do whatever else...
end

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by