Error loading a matrix
Show older comments
Hi,
I have a saved bidimensional array on a .m file called pauta.m:
lab = [523.251 0.125;...
523.251 0.0625;...
659.255 0.0625;...
523.251 0.0625;...
493.88 0.5;...
440.00 2;...
392.00 1];
When I want to use it on the main script, MatLab returns this error:
Error in MiniProj (line 6) for n = 1:length(pauta)"
This is the main script:
Fs = 44100;
all_notes = [];
for n = 1:length(pauta)
x = signal_1(Fs,pauta(n,1),pauta(n,2));
%plot(x);
all_notes = [all_notes x];
end
sound(all_notes,Fs)
Any thoughts? Thank you in advance.
Best regards, Sérgio Pereira.
Answers (1)
per isakson
on 9 Jan 2015
Edited: per isakson
on 9 Jan 2015
I think you should convert pauta to a function
function val = pauta( rr, cc )
lab = [523.251 0.125
523.251 0.0625
659.255 0.0625
523.251 0.0625
493.88 0.5
440.00 2
392.00 1 ];
val = lab( rr, cc );
end
(error checking and efficiency set aside)
 
... or, but I hesitate to show it. (I think it smells.)
Create a script, pauta_script.m, which reads
pauta = [ 523.251 0.125
523.251 0.0625
659.255 0.0625
523.251 0.0625
493.88 0.5
440.00 2
392.00 1 ];
and modify the main script to read
Fs = 44100;
pauta_script;
all_notes = nan( 1, length( pauta ) );
for n = 1:length(pauta)
x = signal_1(Fs,pauta(n,1),pauta(n,2));
%plot(x);
all_notes( 1, n ) = x;
end
sound(all_notes,Fs)
Here I pre-allocated all_notes to the correct length. I use nan beause I guess signal_1 should not return nan and it is thus easy to check whether all element have been assigned values signal_1.
Categories
Find more on Resizing and Reshaping Matrices 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!