Error: Index exceeds the number of array elements (0) on the linspace function

2 visualizzazioni (ultimi 30 giorni)
I have a following part of a long code that plots two data, Variables (time, value) and frequency ( the same start and end of time of the variables but different values).
The code already does what I want, it plots so many figures until it stops with the following error at the fourth line of the code:
Index exceeds the number of array elements (0).
Error in duration/parenReference (line 17)
that.millis = this.millis(rowIndices);
Error in Erstellungderfrequenzinputbox (line 99)
ftime3=linspace(Uhrzeit(1),Uhrzeit(end),height(freqbereich3));
freq3 = freqbereich3.fb3;
freq3 = double(split(string(freq3(2:end-1)) , ","));
freq3 = freq3(:,1);
ftime3=linspace(Uhrzeit(1),Uhrzeit(end),height(freqbereich3));
freqbereich3.ftime3=ftime3';
nexttile
plot(ftime3(2:end-1),freq3);
hold on
plot(Uhrzeit,Wert)
Uhrzeit is the time and freqbereich3 are both all long tables with values that should have the same length or the same number of values that's why I used the linspace. Any solution or help?

Risposta accettata

Walter Roberson
Walter Roberson il 27 Nov 2020
ftime3=linspace(Uhrzeit(1),Uhrzeit(end),height(freqbereich3));
If Uhrzeit is empty then Uhrzeit(1) would be out of range.
  2 Commenti
Ramo Rafsel
Ramo Rafsel il 27 Nov 2020
I just saw that Uhrzeit was empty. And because of the loop it changes its value everytime for each of the Variables that are written in the "Us" variable.
I guess one of the variables has an empty Uhrzeit or no time at all, is there a way how to prevent the error to continue to plot?
Thank you for pointing out the mistake :)
%For-Schleife zum Plotten von den Variablen
for k = 1:numel(U)
T= [Table1;Table2]; %Aufsummieren der beiden Tabellen in einer.
Us = ["Variable1";"Variable2";"Variable3";"Variable4";"Variable5";..;"Variable40"];%Eingabe der Variablen;
U = categorical(Us); %Umwandling des Datentyps von Zelle zum Categorical.
Var = Variableunits.Variable;
Num = size(Var,1);
X = T.Variable==U(k);
Uhrzeit = round(seconds(T.Time(X)/1000)); %Umwandlung der Uhrzeit zum Format HH:MM:SS
Uhrzeit.Format='hh:mm:ss';
Uhrzeit = sort( Uhrzeit,'ascend');
Wert = T.Value(X);
if (answer == "ja") % Wenn ein Zeitstempel vorhanden ist
ind = find(Uhrzeit >= st & Uhrzeit <= et);%Die Uhrzeit zwischen Anfangsuhrzeit und Endzeit einschränken
Uhrzeit = Uhrzeit(ind);
Wert = Wert(ind);
end
switch answer
case 'Frequenzbereich 1'
freq1=freqbereich1.fb1; % Werte des ersten Frequenzbereichs
freq1 = double(split(string(freq1(1:end-1)) , "."));
freq1 = freq1(:,1);
ftime1=linspace(Uhrzeit(1),Uhrzeit(end),height(freqbereich1));
freqbereich1.ftime1=ftime1';
nexttile
yyaxis left
plot(ftime1(1:end-1),freq1);
hold on
yyaxis right
plot(Uhrzeit,Wert)
for i = 1:Num
if Var(i) == U(k)
thisunit = Variableunits.Unit(i);
if ismissing(thisunit)
thisunitname = '';
else
thisunitname = string(thisunit);
end
legend('Frequenzbereich1','Messvariable');
title(string(Var(i)) + " " + thisunitname + " 10^" + string(Variableunits.NKS(i)), 'Interpreter', 'none');
end
end
hold off
end
end
Walter Roberson
Walter Roberson il 27 Nov 2020
T= [Table1;Table2]; %Aufsummieren der beiden Tabellen in einer.
You do not assign to Table1 or Table2 within the loop, so that assignment is going to do the same thing on every loop iteration. I think you need to insert code that modifies Table1 or Table2

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Language Fundamentals in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by