Change [ ] cells in .mat file to NaN

1 回表示 (過去 30 日間)
University Student
University Student 2021 年 2 月 23 日
コメント済み: Rik 2021 年 2 月 23 日
I need help with writing a script that will change the '[ ]' cells to 'NaN' in a .mat file I am working with that is a 1x30 matrix.
The code below does not work:
clear
load('Some_file.mat')
for i = 1:size(Some_file.xyz)
if strcmp(Some_file.xyz,'[ ]')
RSome_file.xyz = NaN;
end
end
  3 件のコメント
University Student
University Student 2021 年 2 月 23 日
Still it is not finding the '[ ]' in the .mat file
Rik
Rik 2021 年 2 月 23 日
Do your cell elements contain the char array '[ ]', or are they only being displayed as such? Please attach the cell array in a mat file.

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

回答 (2 件)

Tesfaye Girma
Tesfaye Girma 2021 年 2 月 23 日
strcmp(Some_file.xyz,'[ ]')
  1 件のコメント
University Student
University Student 2021 年 2 月 23 日
That is the same thing I wrote

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


per isakson
per isakson 2021 年 2 月 23 日
編集済み: per isakson 2021 年 2 月 23 日
I don't fully understand your question.
  • See: TUTORIAL: how to ask a question (on Answers) and get a fast answer
  • "The code below does not work:" What does it? Does it throw an error? If so, what error message?
  • "a 1x30 matrix" cannot contain empty cells (/elements). I interpret '[ ]' as a symbol for empty.
  • Some_file.xyz looks like a structure with a field. Where does it come from?
  • etc.
An example to help me figure out:
>> clearvars
>> a = 1;
>> xyz = [];
>> vec = ones(1,30);
>> save('Some_file.mat')
>> clearvars
>> load('Some_file.mat')
>> whos
Name Size Bytes Class Attributes
a 1x1 8 double
vec 1x30 240 double
xyz 0x0 0 double

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by