saving values without index
7 views (last 30 days)
Show older comments
%***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
0 Comments
Answers (2)
Matt Tearle
on 1 Mar 2012
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 Comments
Walter Roberson
on 1 Mar 2012
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.)
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!