How to convert a table to a 2d array

3 次查看(过去 30 天)
waleed khalid
waleed khalid 2020-11-5
编辑: dpb 2020-11-5
I have 25 csv files that I have I have taken and stored into a temp Table, which was then vertically concatenated into a large table, I want to convert this large table (rpll) into a 2d array so that I can access the row values with a for-loop, what would be the best way of doing this?
rpll=cell(1,data.numberofselected); %Table of all selected csv's ordered by run number aescending
x=cell(1, numel(dir(file_location))); %temp table to store each run which is then concatenated into one large table after this for-loop
for i=1:data.numberofselected
concatenated=strcat(strcat(strcat(file_location,'RUN'),string(data.selected_runs(i))),'.csv');
x{i}=readtable(concatenated);
end
rpll=vertcat(x{:}); %convert into 2d array
for lp = 1:data.numberofselected
i = data.selected_runs(lp);
switch(rpll(3)) ...... %I want to check the 3rd value in every row

回答(1 个)

dpb
dpb 2020-11-5
Don't make a cell array of tables to start with...
x=[];
for i=1:data.numberofselected
concatenated=strcat(strcat(strcat(file_location,'RUN'),string(data.selected_runs(i))),'.csv');
x=[x;readmatrix(concatenated)];
end
  2 个评论
waleed khalid
waleed khalid 2020-11-5
This obfuscates my data to a mix of 0's and 0.0010's.
dpb
dpb 2020-11-5
编辑:dpb 2020-11-5
Well, that's what you asked for -- a 2D array. If data have disparate ranges, MATLAB displays scaled values at command line depending upon what you choose for the FORMAT specifier.
We don't have/can't see your data from here so:
  1. Don't know if the data are actually commensurate to read with readmatrix or not, or
  2. If are, what are actual data values.
All we know about is what is posted here...if you need more specific help, attach a (section of) a typical file.
ADDENDUM:
NB: The data are storedl at full precision; it is only output format that is affected.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by