Bug in tdfread() / str2num()?

3 ビュー (過去 30 日間)
Steffen
Steffen 2013 年 10 月 11 日
コメント済み: sixwwwwww 2013 年 10 月 11 日
Hello,
I observed a strange behaviour when calling
str2num('Xrw_LowConc_QCCmpds_AllMeanFt_q01')
A numeric result is returned rather than an empty matrix:
>> X = str2num('Xrw_LowConc_QCCmpds_AllMeanFt_q01');
>> size(X)
ans = 275 1638
>> [min(X(:)) max(X(:))]
ans = -20.2856 26.8534
This occurred when I tried to read a tab seperated file with tdfread() where the string 'Xrw_LowConc_QCCmpds_AllMeanFt_q01' is a value in one of the columns, producing this error:
In an assignment A(I) = B, the number of elements in B and I must be the
same.
Error in tdfread (line 182)
x(~xempty) = y;
Is this a bug in the str2num() function? Is there another way to read my tab separated file?
Thanks, Steffen.

回答 (3 件)

Jan
Jan 2013 年 10 月 11 日
Did you read the documentation of str2num?
Note str2num uses the eval function to convert the input argument. Side effects can occur if the string contains calls to functions. Using str2double can avoid some of these side effects.
So what exactly is 'Xrw_LowConc_QCCmpds_AllMeanFt_q01' and why do you expect it to create an empty matrix? Due to the problems coming from eval I do not use str2num, but always rely on sscanf directly.
  1 件のコメント
Sean de Wolski
Sean de Wolski 2013 年 10 月 11 日
or str2double

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


sixwwwwww
sixwwwwww 2013 年 10 月 11 日
Dear Steffen, I checked
X = str2num('Xrw_LowConc_QCCmpds_AllMeanFt_q01');
but got empty value because it is not valid string input. Also
size(X)
returns
0 0
So I think you should recheck your workspace variables maybe there is another variable also named as X.

Steffen
Steffen 2013 年 10 月 11 日
編集済み: Steffen 2013 年 10 月 11 日
I did not call
str2num('Xrw_LowConc_QCCmpds_AllMeanFt_q01')
directly. str2num was called with this value by the tdfread() function in the statistics toolbox when I tried to read a tab-separated file that contains the string 'Xrw_LowConc_QCCmpds_AllMeanFt_q01' and resulted in the error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in tdfread (line 182)
x(~xempty) = y;
@sixwwwwww: Which Matlab version do you have? I have 2012a. I'm sure my workspace is okay:
>> clear all
>> X = str2num('Xrw_LowConc_QCCmpds_AllMeanFt_q01');
>> size(X)
ans =
275 1638
  1 件のコメント
sixwwwwww
sixwwwwww 2013 年 10 月 11 日
I am using MATLAB R2013b. Can you share your file and code?

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by