I'm trying to operate on each element of a row vector individually but unable to do so, as each element is containing a vector within itself.

2 views (last 30 days)
Utsav Pandya
Utsav Pandya on 24 Apr 2022
Commented: Dyuman Joshi on 24 Apr 2022
I am executing the following logic:
% specify file location containing multiple .wav files %
% read all files from that location. there are 535 files. %
% convert all the .wav files into .mat files by using readall() %
% it gives numerical representation of each .wav file, giving N co-efficients for each .wav file, there are 535 such .wav files. N can be different for different .wav file. %
% the obtained .mat files is a 535X1 cell. Each cell is a different sized vector, say NX1. %
% i am trying to obtain each individual N, operate on it and then proceed further. But I am unable to do so.%
Is there a way to extract each element of the row vector and operate ono it, within a loop?
Below is the code that I tried:
clc;clear all,close all;
location = fullfile('G:\Mtech_2nd\Minor Project\EMODB_535_folders_final\EMODB_535_folders_final');
ads = audioDatastore(location,'IncludeSubFolders',true,...
'LabelSource','foldernames'); % obtains file location containing .wav files
allsignals = readall(ads); % converts .wav to .mat files, giving 'allsignals' as a 535X1 cell
X = [];
for k=1:535
X = [X allsignals(k)]; %want to operate on each element of this vector
%Y = emd(X,'Interpolation','pchip','Display',1);
Dyuman Joshi
Dyuman Joshi on 24 Apr 2022
You can use cellfun or a loop with numel as @DGM mentioned in their answer. But since you want to process of each element further, a loop will be a better option. use allsignals{k} to extract an element

Sign in to comment.

Answers (1)

DGM on 24 Apr 2022
I think what you're asking is to get the number of elements for each vector within the cell array. You can do that either with a loop or with cellfun().
% sample array
cellofvecs = { (1:3) (1:10) (1:100)};
% with cellfun
N1 = cellfun(@numel,cellofvecs)
N1 = 1×3
3 10 100
% with a loop
N2 = zeros(size(cellofvecs));
for k = 1:numel(cellofvecs)
N2(k) = numel(cellofvecs{k});
N2 = 1×3
3 10 100




Community Treasure Hunt

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

Start Hunting!