Doubles Output in Matrix?

9 次查看(过去 30 天)
New to Matlab so please forgive me. I'm trying to create a matrix, mom, that updates with data from the 4th column of each file that's read:
myDir = uigetdir;
my_mom_Files = dir(fullfile(myDir,'MRFbeam-Mom-*.txt'));
mom = [];
for k = 1:length(my_mom_Files)
baseFileName = my_mom_Files(k).name;
fullFileName = fullfile(myDir, baseFileName);
%fprintf(1, 'Now reading %s\n', fullFileName);
mom_data = load(fullFileName);
mom_col = mom_data(:, 4);
mom = [mom; {mom_col}];
end
The output is as follows:
{ 6181×1 double}
{ 7849×1 double}
{ 3107×1 double}
{ 3107×1 double}
{ 2999×1 double}
{ 2999×1 double}
{ 2000×1 double}
{ 2000×1 double}
{ 2999×1 double}
{ 2999×1 double}
{ 4425×1 double}
{ 6181×1 double}
{ 4425×1 double}
{ 2499×1 double}
{ 2499×1 double}
{11293×1 double}
{11293×1 double}
{29980×1 double}
{29980×1 double}
{ 4825×1 double}
{ 4825×1 double}
{ 1123×1 double}
{ 1123×1 double}
{ 2225×1 double}
{ 2225×1 double}
{ 2221×1 double}
{ 2221×1 double}
{ 7849×1 double}
When I try cell2mat, the size of my matrix changes from 28 x 1 to in the thousands.
Ultimately I would like to print the value found for each file and store it in a matrix. My final goal is to plot these values.
TYIA

采纳的回答

Image Analyst
Image Analyst 2021-9-23
Why are you making it a cell array? No need for that. Assuming all the columns are the same height, just stuff it into a column of a preallocated matrix:
myDir = uigetdir;
my_mom_Files = dir(fullfile(myDir,'MRFbeam-Mom-*.txt'));
numFiles = length(my_mom_Files)
numRows = 10; % Whatever -- it's the number of rows in mom_data.
mom4 = zeros(runRows, numFiles);
for k = 1 : numFiles
baseFileName = my_mom_Files(k).name;
fullFileName = fullfile(myDir, baseFileName);
%fprintf(1, 'Now reading %s\n', fullFileName);
mom_data = load(fullFileName);
thisColumn4 = mom_data(:, 4);
mom4(:, k) = thisColumn4;
end
  6 个评论
Image Analyst
Image Analyst 2021-9-24
Try this:
Then set a breakpoint and learn why thisColumn4 is all zeros. Or why numfiles is zero so the loop never gets entered.
nogooduser
nogooduser 2021-9-29
Hi! Sorry for the delayed response. I plotted and your code works beautifully! Thank you so much for your help.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by