Clear Filters
Clear Filters

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

1 view (last 30 days)
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 Comments
Ray
Ray on 5 Oct 2015
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)

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 15 Sep 2015
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 Comments
Walter Roberson
Walter Roberson on 15 Sep 2015
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!