How to store data in a matrix, but not to overwrite values

1 view (last 30 days)
I want to save the results of a for loop into a matrix, but the results are always getting overwritten,so only the last value is written. I want to save variable seg1 into a matrix. How can I do it? (This code is splitting audio signal into segments). I tried with this code:
[data,Fs] = audioread('sz08010103404.wav');
list = fopen('intervals.txt','r');
C=cell(size(list))
%split the signal
N = length(data);
totaldur = N/Fs; % total duration
t = linspace(0,totaldur,N); % create a time vector
for k=1:length(list)
content = fgets(list(k))
d= strsplit(content,',')
for n=1:length(d) %d contains 25 elements
y=d{n}
z= strsplit(y,' ')
start=z{1}
stop=z{2}
start1 = str2num(start)
stop1 = str2num(stop)
seg1 = data(t>start1 & t<stop1)
sound(seg1)
A=[seg1] %output needs to go here
end
end

Answers (1)

Walter Roberson
Walter Roberson on 20 Feb 2017
A{k} = seg1;

Categories

Find more on Multidimensional Arrays 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!