I have the following data structure (a cell array populated with vectors):
sigvecarray = {};
freqarray = {};
% Reading the audio files, getting the signal vector and the corresponding
for k = 1:numel(inputarray) % indices
curr_input = inputarray{k};
[y, Fs] = audioread(curr_input);
sigvecarray{k} = y;
freqarray{k} = Fs;
end
I'm trying to plot them over a for loop by using the following:
for k = 1:numel(sigvecarray)
plot(sigvecarray{k})
end
But I get only the fist vector plotted as my output. What could I be doing wrong here? Is it because the cell array is a row vector? If yes, how do I convert the cell array to a column vector from a row vector?

 채택된 답변

KSSV
KSSV 2020년 10월 12일

1 개 추천

figure
hold on
for k = 1:numel(sigvecarray)
plot(sigvecarray{k})
end

댓글 수: 5

skrowten_hermit
skrowten_hermit 2020년 10월 12일
Okay. This seems to be plotting them but on top of each. Should I use subplots then?
Okay. A bit of playing around and the following plotted each of the vectors just fine:
for k = 1:numel(sigvecarray)
figure;
hold on;
plot(sigvecarray{k})
end
Thanks for the pointers.
Yes, you can use subplot if you want it on different plots. You can use subplot in a loop depending on how many plots are there.
k = 5;
for i = 1:k
subplot(k,1,i)
plot(rand(1,10))
end
I had tried out subplots before. They seem to shrink the plots to fit the screen when I do:
for k = 1:numel(sigvecarray)
subplot(length(sigvecarray), 1, k)
plot(sigvecarray{k})
end
Is there a way to decide the size (in pixels for example) of each plot? Say 640x480 or something like that?
KSSV
KSSV 2020년 10월 12일
Possible you need to set the size of whole figure etc....read the doc.

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

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 12일
편집: Ameer Hamza 2020년 10월 12일

1 개 추천

hold on
will add new lines on the same axes without deleting old lines.

댓글 수: 3

skrowten_hermit
skrowten_hermit 2020년 10월 12일
편집: skrowten_hermit 2020년 10월 12일
Hi Ameer,
I had tried out subplots before. They seem to shrink the plots to fit the screen when I do:
for k = 1:numel(sigvecarray)
subplot(length(sigvecarray), 1, k)
plot(sigvecarray{k})
end
Is there a way to decide the size (in pixels for example) of each plot. The help page you shared didn't seem to have that option.
Ameer Hamza
Ameer Hamza 2020년 10월 12일
You need to use the Position property of the axes object to change their size. An alternative might be to use
nexttile(): https://www.mathworks.com/help/matlab/ref/nexttile.html. Though I am not sure if there is a significant difference.
skrowten_hermit
skrowten_hermit 2020년 10월 12일
Thanks. Looks promising. I'll definitely try nexttile().

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

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

릴리스

R2017b

태그

질문:

2020년 10월 12일

댓글:

2020년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by