필터 지우기
필터 지우기

How to store data into a matrix?

조회 수: 1 (최근 30일)
Lara Lirnow
Lara Lirnow 2017년 3월 13일
답변: Guillaume 2017년 3월 13일
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
Jan
Jan 2017년 3월 13일
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"?
Lara Lirnow
Lara Lirnow 2017년 3월 13일
Hi, I edited my question. I hope I explained it a bit better. Thank you

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

채택된 답변

Guillaume
Guillaume 2017년 3월 13일
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

추가 답변 (1개)

Lara Lirnow
Lara Lirnow 2017년 3월 13일
I solved my question. I got that output like this:
F{i} = {energyST,numZeroCross}

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by