Error with converting class of matrix
2 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Aditya
on 24 Jan 2025
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!
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!