Unable to concatenate the table variables
7 ビュー (過去 30 日間)
古いコメントを表示
I am using readtable command to read data from .csv file as given below. One of the column contains varying quantity, and I would like to specify those values in commandwindow. How can I achieve this.
In the below code, I am getting error saying ''Unable to concatenate the table variables''. How to resolve this?
Thank you
R1 = 0.02; R2 = 0.03;
my_data_1 = readtable('my_data.csv')
my_data_2 = table2array(my_data_1(:,1:4));
4 件のコメント
Stephen23
2022 年 6 月 13 日
"That is values assigned to R1 and R2 are of class 'complex'. "
MATLAB does not have a "complex" class type. Here are the fundamental MATLAB classes:
R1 could be char, or string, or categorical, or something similar.
Walter Roberson
2022 年 6 月 13 日
The code is expecting that when the file is read, that any variable names in the text will be replaced with the value of the variable. However, MATLAB does not provide any file reading routines that will do that.
If you read the entire file as a character vector, and put '[' before and ']' after, and evalc() then possibly you would get what you are after.
... At least until someone puts
system('format C:\')
into an input file for the lulz.
回答 (1 件)
Walter Roberson
2022 年 6 月 12 日
Your Z column contains text but your other columns are numeric. It is not possible to create a single array that contains both text and numeric, other than converting to a cell array such as by using table2cell()
Note: when you assign values to variables, such as the way you assign to R1 and R2 here, and then you try to read from a file that contains text that matches variable names... then the values of the MATLAB variables will not be automatically substituted where the text occurs.
Also note that Excel has no way to represent complex numbers, so the 0.01+0.1j can only be read in as text.
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!