フィルターのクリア

Script works on Windows OS but not on MacOS

1 回表示 (過去 30 日間)
Ferhat Kangal
Ferhat Kangal 2022 年 12 月 22 日
コメント済み: Steven Lord 2022 年 12 月 22 日
Hello everybody,
I am trying to SMOTE data augmentation for a image dataset but the script I evaluate works on Windows OS but not on MacOS. Part of the code is below and it's like;
labels=[];info=strfind(files,'\');
Unrecognized function or variable 'files'.
for i=1:numel(files)
idx=info{i};
dirName=files{i};
targetStr=dirName(idx(end-1)+1:idx(end)-1);
targetStr2=cellstr(targetStr);
labels=[labels;categorical(targetStr2)];
end
and the error I'm having is;
Array indices must be positive integers or logical values.
Error in smote (line 24)
targetStr=dirName(idx(end-1)+1:idx(end)-1);
anyone has any idea why I'm having that problem?

回答 (1 件)

Jan
Jan 2022 年 12 月 22 日
編集済み: Jan 2022 年 12 月 22 日
Use the debugger to identify the problem. Type this in the command window:
dbstop if error
Then run the code again. If Matlab stops at the error, check the values of the variables:
dirName
idx
idx(end-1)+1
idx(end)-1
If idx is a scalar, idx(end-1) requests the 0th element, which is failing.
This can happen, because MacOS and Windows use different file separators. Therefore this is a bad idea:
info=strfind(files,'\');
% Better:
info=strfind(files, filesep);
Another option is to use fileparts instead of handmade parsing of paths.
  2 件のコメント
Ferhat Kangal
Ferhat Kangal 2022 年 12 月 22 日
Thanks for your reply. I have just solved the problem using "/" instead of "\". Thank you!
Steven Lord
Steven Lord 2022 年 12 月 22 日
You haven't fixed the problem by switching from hard-coded '\' to hard-coded '/'. You've just changed on which OS your code works and on which OS it doesn't.
I second Jan's suggestions to use either filesep or fileparts (and if you need to reassemble a file path from parts use fullfile.)

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by