Avoid overwriting value of variable

18 ビュー (過去 30 日間)
Ghenji
Ghenji 2018 年 2 月 14 日
編集済み: Stephen23 2018 年 2 月 14 日
I am having following code:
Source_files = [specified directory]
len = length(Source_files);
for j = 1 : len
[status,sheets] = xlsfinfo(Source_files)
sheetIndex = find(strncmp(sheets, '#', 1));
end
sheetIndex variable's value gets overwritten on every iteration. I want to have a variable wanted_sheets constituting names of all the sheets starting with '#' from all the files.

採用された回答

Stephen23
Stephen23 2018 年 2 月 14 日
編集済み: Stephen23 2018 年 2 月 14 日
Use indexing:
Source_files = [specified directory]
N = numel(Source_files);
C = cell(1,N);
for k = 1:N
[status,sheets] = xlsfinfo(Source_files{k});
C{k} = find(strncmp(sheets, '#', 1));
end
  2 件のコメント
Ghenji
Ghenji 2018 年 2 月 14 日
編集済み: Ghenji 2018 年 2 月 14 日
Thank you for your reply, Now this gives me only sheet number for this files. How do i get sheetnames?
Secondly, this numbers(sheet no.) are repeating how can i avoid this?
lets say I have these files with their sheetnames:
File1 : #sheet1, sheet2, #sheet3, sheet4, sheet5
File2 : sheet1, sheet2, #sheet3, #sheet4, sheet5
File3 : #sheet1, sheet2, #sheet3, sheet4, sheet5
This is how i want,
wanted_sheet = #sheet1, #sheet3, #sheet4
Stephen23
Stephen23 2018 年 2 月 14 日
編集済み: Stephen23 2018 年 2 月 14 日
First collect the sheet names, then do any processing after the loop:
N = numel(Source_files);
C = cell(1,N);
for k = 1:N
[~,C{k}] = xlsfinfo(Source_files{k});
end
C = [C{:}];
C = C(strncmp(C,'#',1));
C = unique(C)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by