Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 commentaires
Ray
Ray le 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)
Walter Roberson
Walter Roberson le 5 Oct 2015
You started a new Question for this and I have answered there.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 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 commentaires
Walter Roberson
Walter Roberson le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by