How to store data into a matrix?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lara Lirnow
am 13 Mär. 2017
Beantwortet: Guillaume
am 13 Mär. 2017
I'm calculating Zerocross (ZCR) and Short term energy (STE) for a signals in a matrix. After I calculate these features I want to store results into one matrix F to contain both features STE and ZCR, like this :
F=[STE1][ZCR1]
[STE2][ZCR2]
[STE3][ZCR3]...
B is 1x59 cell array which cells are matrixes B = {[240x1], [480x1],[960x1] ...} so each cell is another matrix.
So I want my output to be like this
F = [240x1][ZCR1]
[480x1][ZCR2]
[960x1][ZCR3] ...
% first column (e.g.[240x1]) is STE calculation of the first column in B, and second column is a calculation of the Zerocross also of the first column of the cell array B..and so on
How can I get that output? My code is next:
for i=1:length(V)
V=B{1,i}
%zerocross
zcd = dsp.ZeroCrossingDetector;
numZeroCross = step(zcd,V)
ZER{i}=numZeroCross %output for zerocross
%short term energy
winLen=length(V)
energyST = sum(V.^2,winLen)
EN{i}=energyST %output for STE
end
2 Kommentare
Jan
am 13 Mär. 2017
Matrix B is 1x59 cell array which looks like this
B = {[240x1], [480x1],[960x1] ...} so each cell is a matrix.
This is not easy to understand. What is "B"? If B is a "matrix", it is not a "cell vector". What is the relation between "B" and the shown "F"? What exactly does "[240x1,ZCR1]" mean? What is "ZCR1"?
Akzeptierte Antwort
Guillaume
am 13 Mär. 2017
I assume that
for i=1:length(V)
is meant to be
for i=1:length(B) %numel instead of length would be safer
otherwise your code makes no sense.
On the same level,
winLen=length(V) %would be 240 for B{1}
energyST = sum(V.^2,winLen) %would sum along dimension 240, so would sum nothing!
is complete nonsense and produces the same result as:
energyST = V.^2;
To answer your question, this should produce the result that you want:
F = cell(numel(B), 2); %preallocate result.
zcd = dsp.ZeroCrossingDetector; %no need to recreate it at each step of the loop
for i = 1:numel(B)
V = B{i}; %simpler and safer than B{i, 1} as it will work whatever the shape of B
F{i, 2} = step(zcd, V);
F{i, 1} = someenergyfunctionof(V);
end
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!