Trying to input a number of files from a matrix

1 回表示 (過去 30 日間)
Saar Peles
Saar Peles 2020 年 9 月 16 日
編集済み: Walter Roberson 2020 年 9 月 17 日
I'm not sure why this isn't working but I'm just trying to load multiple files from a folder and it's not reading my variables in the matrix as a string. I tried converting to chars but I obviously need more than 1 char based on the example below.
subName = ["10", "12"];
InputFolder = 'F:\Graph Data\';
for i = 1:(size(subName)) %through the size of the number of input files
load([InputFolder,'S',(subName(i)),'_data']);
end
I'd appreciate any help

採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 16 日
>> subName = ["10", "12"]; size(subName), 1:size(subName)
ans =
1 2
ans =
1
size() with a single parameter always returns a vector with at least two elements. When you give the colon operator a non-scalar value (such as a vector of length 2), then it ignores everything except the first value... which in this case is 1, the number of rows in subName.
load([InputFolder,'S',(subName(i)),'_data']);
You should probably be using something like
load( fullfile(InputFolder, "S" + subName(i) + "_data.mat") )
and better yet would be to assign the result of load() to a variable, instead of "poofing" variables into existence.
  2 件のコメント
Saar Peles
Saar Peles 2020 年 9 月 17 日
Thanks I appreciate the help. One thing though, what would I use in place of size()?
Walter Roberson
Walter Roberson 2020 年 9 月 17 日
編集済み: Walter Roberson 2020 年 9 月 17 日
numel()

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by