table2array gives string array when contents are numbers

Whenever I try to convert an table of numbers into an array, instead I will get a string array with all my numbers listed inside quotemarks. When I try to access it with {} which is reccommended elsewhere in matlab answers then the problematic column that I just added to the matrix here just dissapears entirely
The line giving the issue is
channel5mmyeild= table2array([sr_p, x5mmlinyeild]);
Anyone have any idea what could be causing this?
Cheers

 採用された回答

Cris LaPierre
Cris LaPierre 2021 年 1 月 4 日

0 投票

I suspect data in sr_p and x5mmlinyeild are chars or strings and not doubles. What is the data type of the columns of your table? Look at the results of summary(sr_p) and summary(x5mmlinyeild).
If that doesn't seem to be the problem, please save your variables to a mat file and attach them to your post using the paperclip icon.

3 件のコメント

Em
Em 2021 年 1 月 5 日
Yes you' were right - 'x5mmlinyeild' is a table of strings.
I've tried
str2num(table2array(x5mmlinyeild))
but it isn't working. Do you have a suggestion on what I need to do next?
How many variables are in the table? How do you create x5mmlinyeild? I would set it up so that the values are doubles.
Still, converting is fairly simple. Here's a simple example.
str = "10";
x5mmlinyeild = table(str);
N=5;
sr_p = table(N);
% Convert table variable(s) to double first
x5mmlinyeild.str = str2double(x5mmlinyeild.str);
channel5mmyeild= table2array([sr_p,x5mmlinyeild])
channel5mmyeild = 1×2
5 10
It would also appear that, when operating on a table of strings, table2array converts a table of strings to doubles.
table2array(x5mmlinyeild)
ans = 10
It is the mixed case that appears to have caused trouble. In that case, it elected to make everything strings instead of everything doubles.
Em
Em 2021 年 1 月 6 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

製品

リリース

R2017a

質問済み:

Em
2021 年 1 月 4 日

コメント済み:

Em
2021 年 1 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by