convert the table to matrix
54 次查看(过去 30 天)
显示 更早的评论
Hi,
I used the below command and it read the dat files as a table (1x1500 cell) and each cell include (65536x4 table)
for k = 1:1500
myfilename = sprintf('Vec%05d.dat', k);
mydata{k} = readtable(myfilename);
end
then I tried to convert the table to matrix, but it doesn't work, could you please correct it to me?
for k = 1:1500
mydata1(:,:,k)= table2array(mydata{:,k})
end
my aim is to get a matrix of mydata1 with size 256x256x1500
thanks in advance
3 个评论
Walter Roberson
2023-12-5
Do you need the intermediate tables to be stored for some reason, or do you just need the final array?
Is there a reason you are using readtable() instead of readmatrix() ?
采纳的回答
Walter Roberson
2023-12-5
N = 1500;
%we proceed in two steps.
%we read one array
for k = 1
myfilename = sprintf('Vec%05d.dat', k);
mydata1 = readmatrix(myfilename);
end
%and that tells us how much data is in each file.
%Now we extend array efficiently. Doing a single
%array extension like this is a heck of a lot faster
%than growing the array each iteration
mydata1(end,end,N) = 0;
%now read the rest of the files
for k = 2:N
myfilename = sprintf('Vec%05d.dat', k);
thisdata = readmatrix(myfilename);
mydata1(:,:,k) = thisdata;
end
%we have all of the data
%reshape it.
%we assume 256 rows but we do not assume columns
mydata1 = reshape(mydata1, 256, [], size(mydat1,2), size(mydata1,3));
0 个评论
更多回答(1 个)
Sulaymon Eshkabilov
2023-12-5
I believe as Madhan pinpointed that you data size should be 256x256x4x1500. Here is the final code:
for k = 1:1500
myfilename = sprintf('Vec%05d.dat', k);
mydata{k} = readtable(myfilename);
mydata1(:,:,k)= table2array(mydata{:,k})
end
%% Final conversion after collecting all data from the files into an ARRAY
MY_data_OK = reshape(MY_data, [256, 256, 4, 1500]);
1 个评论
Mohamed
2023-12-5
Actually, I am not sure that: mydata1(:,:,k)=table2array(mydata{:,k})
This command worked for a day without stopping. So I could you please tell me where is the mistake because I think it is just a loop
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!