필터 지우기
필터 지우기

saving values without index

조회 수: 8 (최근 30일)
zozo
zozo 2012년 3월 1일
%***question updated***%
I have the following situation:-
for d=1:numel(Time_delay) % time delay is (8x1000) matrix
if rem(d,8)==0;
mic_out(1,:)=mic_in(1,:);
out(rem(d,8)+1,:)=sum(mic_out,1);
y=sum(out.^2,2);
mic_out=zeros(size(mic_out));
end
mic_out(rem(d,8)+1,:)= del(mic_in(rem(d,8)+1,:),fs,Time_delay(d+1),2000); %here 'del' is a function which delays the 8 signals in 'mic_in(8x10000)' according to delays specified in Time_delay'
end
The first row in Time_delay is all zeros. So, there is no delay applied. Hence, I replace it with 1st row of signal that is, mic_in(1,10000). Each time I change column in Time_delay, I need to add the 8 delayed signals in mic_out row-wise,square it and add them colum wise(i.e. calculate energy) and store only the energy value and move on.
Then repeat the above process for all columns of Time_delay.
At the end I need only 'y' matrix containing the energies.
Whats the most efficient way to achive this? Please help

답변 (2개)

Matt Tearle
Matt Tearle 2012년 3월 1일
Why do you not want to use an index? It is less efficient to just append values to an existing array, but you can:
x = [];
for k = 1:5
x = [x,k^2];
end
or even x(end+1) = ...
If the values are of different types or dimensions, use a cell array -- e.g.:
x = {};
for k = ...
x{end+1} = ... % or x = [x,...];
end
  댓글 수: 4
zozo
zozo 2012년 3월 1일
@walter: Please check the above question(updated).
zozo
zozo 2012년 3월 2일
please help-

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


Walter Roberson
Walter Roberson 2012년 3월 1일
Using the index "end+1" is often clearer coding. It is not clear why indexing should be avoided.
But anyhow, the following technically does not use any indexing:
results = [];
for K = 1 : 20
newvalue = rand(); %whatever the new value should be
results = [results; newvalue]; %add it to the end
end
This is not efficient (before R2011a anyhow.)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by