# Error while sub plotting

2 visualizzazioni (ultimi 30 giorni)
John Carroll il 24 Feb 2021
Commentato: Walter Roberson il 24 Feb 2021
Hello I am trying to plot 6 subplot to one figure. However when i run my code i am reciving a figure with only one plot witch is empty. Along with the plots not having any data the axis are not visble either. Any help would be much appricated.
My code as follows:
twoHZ = table2array(Y2);
two = detrend(twoHZ);
for i=1:32
[pks] = findpeaks(two(:,i));
meanWH(i) = mean(pks);
end
mn1 = mean(meanWH);
WH2 = mn1*2
fourHZ = table2array(Y4);
four = detrend(fourHZ);
%not enough points to get waveheight
eightHZ = table2array(Y8);
eight = detrend(eightHZ);
for i=1:32
[pks] = findpeaks(eight(:,i));
meanWH(i) = mean(pks);
end
mn1 = mean(meanWH);
WH8 = mn1*2
sixteenHZ = table2array(Y16);
sixteen = detrend(sixteenHZ);
for i=1:32
[pks] = findpeaks(sixteen(:,i));
meanWH(i) = mean(pks);
end
mn1 = mean(meanWH);
WH16 = mn1*2
thirtytwoHZ = table2array(Y32);
thirtytwo = detrend(thirtytwoHZ);
for i=1:32
[pks] = findpeaks(thirtytwo(:,i));
meanWH(i) = mean(pks);
end
mn1 = mean(meanWH);
WH32 = mn1*2
X2 = (0:0:10);
X4 = (0:0:20);
X8 = (0:0:47);
X16 = (0:0:85);
X32 = (0:0:180);
figure (1)
subplot(2,3,1)
plot(X2,twoHZ,'b--');
xlabel('time(sec)')
ylabel('height (m)')
title('Two Hz')
subplot(2,3,2)
plot(X4,fourHZ,'g--');
xlabel('time(sec)')
ylabel('height (m)')
title('Four Hz')
subplot(2,3,3)
plot(X8,eightHZ,'r--');
xlabel('time(sec)')
ylabel('height (m)')
title('Eight Hz')
subplot(2,3,4)
plot(X16,sixteenHZ,'r--');
xlabel('time(sec)')
ylabel('height (m)')
title('Sixteen Hz')
subplot(2,3,5)
plot(X32,thirtytwoHZ,'r--');
xlabel('time(sec)')
ylabel('height (m)')
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Walter Roberson il 24 Feb 2021
Modificato: Walter Roberson il 24 Feb 2021
nnz(isnan(thirtytwoHZ))
nnz(~isfinite(thirtytwoHZ))

Accedi per commentare.

### Risposte (1)

Just Manuel il 24 Feb 2021
Modificato: Just Manuel il 24 Feb 2021
X2 = (0:0:10);
X4 = (0:0:20);
X8 = (0:0:47);
X16 = (0:0:85);
X32 = (0:0:180);
when you specify zero as the element spacing with the column operator, you end up with an empty row vector.
You did not mention that matlab complained about "Vectors must be the same length.", so i expect that also twoHZ, etc. are empty.
However, I suspect, matlab did give you that error and you just forgot to tell us :)
figure (1)
subplot(2,3,1)
creates the empty plot.
plot(X2,twoHZ,'b--');
will then produce the error and abort execution of your script. This is why you end up with only one empty plot.
Cheers
Manuel
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Walter Roberson il 24 Feb 2021
Good catch, I did not notice the :0:

Accedi per commentare.

### Categorie

Scopri di più su Subplots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by