How can I create a matrix that contains number and text without using the cell array?
2 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1284175/image.jpeg)
Hi,
I need to turn a structure into a matrix (as an Excel-like table - see above). I can transpose the single data stored in the different fields to create my table (as I did above), but I can't add columns containing text. I know I am supposed to create a cell array, but my goal is to have all my data in a single matrix that I can open in R for analysis. I'm also trying to open a cell array in R but doesn't really work well.
Thank you very much!
Riccardo
2 个评论
Walter Roberson
2023-2-3
Unfortunately https://www.rdocumentation.org/packages/rmatio/versions/0.12.0/topics/read.mat says almost nothing about what kinds of variables it can read in R.
the cyclist
2023-2-4
Yeah, the unfortunate practical reality is that converting to CSV is almost always the way to communicate between statistical software languages.
回答(2 个)
the cyclist
2023-2-3
编辑:the cyclist
2023-2-3
Then, how you choose to export the data from MATLAB will also be important. You can use the writetable function for that.
0 个评论
Sulaymon Eshkabilov
2023-2-3
The most efficientw ay of getting this exercise done is wot use writetable():
% (1) Some structure data:
A.Data1 =(1:10).';
A.Data2=randn(10,1)*10;
A.TXT = [''; ''; 'abc'; 'bac'; 'cba'; 'cab'];
% (2) Convert it into a table array
B = array2table(A.Data1);
B.Var2 = A.Data2;
% (3) Write them (numerical and textual data) into MS Excel using writetable()
writetable(B, 'RData.xls', 'WriteVariableNames',false, 'Sheet', 1);
C = table(A.TXT);
writetable(C, 'RData.xls', 'WriteVariableNames',false, 'Sheet', 1, 'Range', 'C5:C10')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!