Error with converting class of matrix

2 次查看(过去 30 天)
Sophia
Sophia 2019-5-16
回答: Aditya 2025-1-24
I want to output a one dimensional list of data from a particular column of certain rows of a table. The data is in the form 123_S_4567, which will not work in a matrix. I have tried creating cells and tables instead to put the data in, but am having troubles with it. There are 376 different 123_S_4567 kind of data that I want to output. Currently I am trying to make an array (or whatever class works) of the predetermined size then filling in each value in a for loop. Sometimes the error I get is that it can't contain string and other times it says the array must have the same height and number of columns. Right now the error is that it can't convert from table to cell.
PTID=cell([1,376]);
...
PTID(:,j)=roster(rownumber,4);
Please let me know if there is an eaier way to do this or if you know what class of matrix or array to use.
Thanks!

回答(1 个)

Aditya
Aditya 2025-1-24
Hi Sophia,
To extract and convert a specific column from certain rows of a table into a cell array, you can use "table2cell" like this:
% Assume 'roster' is your table and 'rownumber' is a vector of row indices
rownumber = [1, 2, 3, 4]; % Example row indices
% 'Column4' is the name of the column you want to extract
PTID = table2cell(roster(rownumber, 'Column4'));
To read more about "table2cell" function please refer to the below documentation link:
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by