How can i Reshape columns for 34400x202 table

조회 수: 4 (최근 30일)
Ömer Faruk Kilic
Ömer Faruk Kilic 2021년 4월 18일
답변: Suraj Kumar 2025년 3월 4일
I'm trying to write a script for music genre classification. I have two different feature matrixes. First matrix takes 80 wav files for each genres. That makes 800 rows and 202 feature columns. My second feature matrix is wavelet. Wavelet feature matrix takes 80 wav files for each genres but it multiplies it by 43. And that makes 800*43 rows and 202 columns as well. How can i reshape it to 800 rows / 202 columns?
ads = audioDatastore(location,'IncludeSubFolders',true,'LabelSource','foldernames');
countEachLabel(ads)
rng(100);
ads = shuffle(ads);
[adsTrain,adsTest] = splitEachLabel(ads,0.8);
numTrain = countEachLabel(adsTrain)
numTest = countEachLabel(adsTest)
trainLabels = adsTrain.Labels;
testLabels = adsTest.Labels;
sn = waveletScattering('SignalLength',2^19,'SamplingFrequency',22050,'InvarianceScale',0.5);
N = 2^19;
batchsize = 64;
scTrain = [];
useGPU = true; % Set to true to use the GPU
while hasdata(adsTrain)
sc = helperbatchscatfeatures(adsTrain,sn,N,batchsize,useGPU);
scTrain = cat(3,scTrain,sc);
end
numTimeWindows = size(scTrain,2);
Nkeep=202; % size to keep
[~,npaths] = sn.paths();
Npaths = sum(npaths);
TrainFeaturesWavelet = permute(scTrain,[2 3 1]);
TrainFeaturesWavelet = reshape(TrainFeaturesWavelet,[],Npaths,1); % wavelet time scattering
TrainFeaturesWavelet = (TrainFeaturesWavelet(1:end,1:Nkeep));
numTrainSignals = numel(trainLabels);
trainLabelsWavelet = repmat(trainLabels,1,numTimeWindows);
trainLabelsWavelet = (reshape(trainLabelsWavelet',numTrainSignals*numTimeWindows,1));
I attached label matrices as png. My point is, in normal train label matrix it goes by blues, clas, disco.... But in wavelet, it goes by same variables but; blues*43 , clas*43, disco*43..
  댓글 수: 2
Sargondjani
Sargondjani 2021년 4월 18일
It is not clear to me what you want...
Ömer Faruk Kilic
Ömer Faruk Kilic 2021년 4월 20일
I mean, i have two different feature matrices. I want to get that 2 matrices in 1 matrix. But my first matrix is 800 rows 202 columns, second matrix is 800*43 rows and 202 columns as well. My second matrix uses same inputs by multiplying 43. I mean for the second matrix, first 80 rows has to be blues and second 80 disco... But it goes as 80*43=3440 rows for blues and 3440 rows for disco and it goes like that. I want to pretend that "multiplying 43" thing. at the end of the day i'm trying to get 1 matrix as 800 rows and 404 columns ---->
800x202 + 800x202
(first matrix) (second matrix which has 43 problem)

댓글을 달려면 로그인하십시오.

답변 (1개)

Suraj Kumar
Suraj Kumar 2025년 3월 4일
From what I understand you want to reshape the second matrix so that it matches the number of rows in the first matrix, effectively compressing the 34400 rows into 800 rows, while maintaining the structure of the data. You can then concatenate the two matrices horizontally to achieve a final matrix of 800 rows and 404 columns.Please refer to the following steps for more information:
1. You can reshape the second matrix by averaging or otherwise combining every group of 43 rows into a single row. This can be done using the reshape and mean functions in MATLAB.To learn more about these functions you can refer to the following steps:
2. Then concatenate the matrices once the second matrix is reshaped to 800 rows with the first matrix.
You can refer to the below MATLAB script for a better understanding:
numOriginalRows = 800;
numColumns = 202;
factor = 43;
% Reshape the second matrix
reshapedWaveletFeatures = reshape(TrainFeaturesWavelet, factor, numOriginalRows, numColumns);
compressedWaveletFeatures = squeeze(mean(reshapedWaveletFeatures, 1));
% Combine the matrices horizontally
combinedFeatures = [TrainFeaturesOriginal, compressedWaveletFeatures];
% Check the size of the final matrix
disp(size(combinedFeatures));
Happy Coding!

카테고리

Help CenterFile Exchange에서 AI for Signals and Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by