Problems running the code in Mac

2 ビュー (過去 30 日間)
Vahagn
Vahagn 2023 年 3 月 6 日
コメント済み: Jan 2023 年 3 月 7 日
Hi,
I have a code that works fine with windows, but returns me an error when I try to run it using mac. Here is my code and my error
for i=1:numel(M_.params)
p.(M_.param_names{i}) = M_.params(i);
end
Brace indexing is not supported for variables of this type.
Here, M_.param_names is 54x8 char and M_.params is 54x1 double.

採用された回答

Jan
Jan 2023 年 3 月 6 日
This will not run on a PC also. If M_.param_names is a 54x8 char, you cannot use braces for indexing, because they work for cells only.
So the actual problem is, why M_.param_names is a CHAR matrix on the Mac, while it must be a cell string on the PC to let the code run. How did you create this variable? Is it an import of a text file, which expects specific line breaks?
  3 件のコメント
Vahagn
Vahagn 2023 年 3 月 7 日
編集済み: Vahagn 2023 年 3 月 7 日
Here, how it looks like
Jan
Jan 2023 年 3 月 7 日
@Vahagn: This looks like a CHAR matrix and as explained already, you cannot access it with curly braces as index. But the conversion to a cell string is easy:
names = cellstr(M_.param_names); % This is a cell string now
for i=1:numel(M_.params)
p.(names{i}) = M_.params(i);
end
cellstr crops the trailing spaces.

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2023 年 3 月 6 日
Indexing into a char array using {} is not supported on any platform.
a = 'abracadabra'
a = 'abracadabra'
a(5) % 'c'
ans = 'c'
a{5} % error
Brace indexing is not supported for variables of this type.
Perhaps your M_.param_names variable is a char array on Mac but a cell array containing char arrays on Windows and/or Linux. How do you create that field of the M_ struct?

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by