How to convert a table to a 2d array

6 views (last 30 days)
waleed khalid
waleed khalid on 5 Nov 2020
Edited: dpb on 5 Nov 2020
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

Answers (1)

dpb
dpb on 5 Nov 2020
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 Comments
waleed khalid
waleed khalid on 5 Nov 2020
This obfuscates my data to a mix of 0's and 0.0010's.
dpb
dpb on 5 Nov 2020
Edited: dpb on 5 Nov 2020
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.

Sign in to comment.

Categories

Find more on Cell Arrays in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!