필터 지우기
필터 지우기

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에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by