フィルターのクリア

str2num change from 2018 to 2021

2 ビュー (過去 30 日間)
Justin Harris
Justin Harris 2023 年 2 月 28 日
コメント済み: Justin Harris 2023 年 2 月 28 日
I have some code to open and use character and number data from a csv file. It successfully runs in Matlab 2018b but no longer works in 2021. Can anyone suggest what needs to change to get this working in matlab 2021? The code is:
text = fileread([csv file name]);
lines = strread(text, '%s','delimiter','\n')
for r = 1:length(lines)
Full_Array(r,:) = str2num(cell2mat(lines(r)));
end
The above lines of code would take open the csv file and create an array containing both numbers and alphanumeric characters. It seems that something has changed about the str2num function so it always returns empty cells.
Thank you.
Justin
  2 件のコメント
Stephen23
Stephen23 2023 年 2 月 28 日
編集済み: Stephen23 2023 年 2 月 28 日
@Justin Harris: please click the paperclip button to upload a sample data file.
I remember that STR2NUM has an interesting bug / feature that allowed it to return structure arrays (and function handles and more recently tables, etc.), but cell arrays and char arrays (and more recently strings) are explicitly checked for and are not returned. So your code must have relied on this (most likely) unintended, undefined, undocumented behavior:
str2num('struct(''x'',{''a'',pi})')
ans = 1×2 struct array with fields:
x
str2num('{''a'',pi}')
ans = []
There seems to be no other way to return "an array containing both numbers and alphanumeric characters".
Justin Harris
Justin Harris 2023 年 2 月 28 日
Yes, the code must have capitalised on that bug. Thanks.

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

回答 (1 件)

Simon Chan
Simon Chan 2023 年 2 月 28 日
Not sure any change on function str2num, but I would use function str2double to try.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by