필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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?

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 27일
ftime3=linspace(Uhrzeit(1),Uhrzeit(end),height(freqbereich3));
If Uhrzeit is empty then Uhrzeit(1) would be out of range.
  댓글 수: 2
Ramo Rafsel
Ramo Rafsel 2020년 11월 27일
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 2020년 11월 27일
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

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by