Combining several files with 18 by 18 matrix in each file into one single file with one single column

1 次查看(过去 30 天)
Hello all,
I have several .mat files each .mat file contains 18 by 18 data files. I am trying to combine each of the 18 by 18 matrix into one single column. After that, i want to combine all the single column files into one file with one single file.
Below is my code but i have a problem on this line:
data.reshapedData(p) = reshape((matData{k}.rawdata),324,1);
---
myFolder = '/Users/redhwanmawari/Documents/MATLAB/2DimenstionalTestingGT20150907/LOS0dbm15ft_finalData'; % Define your working folder
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.mat');
matFiles = dir(filePattern);
%for k = 1:length(matFiles)
p=1;
for k = 1:5
baseFileName = matFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
%matData(k) = load(fullFileName);
matData{k} = load(fullFileName);
data.reshapedData(p) = reshape((matData{k}.rawdata),324,1);
% p=p+324;
end
  2 个评论
Ray
Ray 2015-10-5
Hi, I am trying to do a 3D plot for 18 by 18 matrix containing a first structure "positions" (x,y coordinates), and a second structure containing "power" in db. I have about 20 files with the position and power structures in each file. I took all the positions from each file and put them in one single structure and the power in another structure. However, the positions repeat after 324 rows (18 X18 = 324). when i tried to plot, i got weird plot. Not sure why, but i am thinking when the positions repeat, the graph does not look right. below is the code i used to do the plot.
load('combine.mat');
Pow=positions.offsetdata;
Pos=[]; for i=1:length(power.positions); Poss=power.positions{i,1}; Pos=[Pos;Poss']; end
figure plot3(Pos(:,1),Pos(:,2),Pow)

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2015-9-15
for k = 1:5
baseFileName = matFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
matData{k} = load(fullFileName);
data.reshapedData(:,:,k) = matData{k}.rawdata;
end
data.reshapedData = data.reshapedData(:);
  4 个评论
Walter Roberson
Walter Roberson 2015-9-15
The line
data.reshapedData(:,:,k) = matData{k}.rawdata;
takes the current matrix and writes it in as slice #k of data.reshapedData.
The line
data.reshapedData = data.reshapedData(:);
is equivalent to
data.reshapedData = reshape( data.reshapedData, numel(data.reshapedData), 1);
which is to say it creates a single column out of all of the data in the matrix, by treating the data column by column for the first slice, then all the columns for the second slice, and so on.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by