필터 지우기
필터 지우기

What does this error " Undefined operator '*' for input arguments of type 'string' " means?

조회 수: 4 (최근 30일)
I have this code (part of a script)
for i=1:N
Size = Event_List(1,4);
Start_trans_time_ONU(i) = CurrentTime + (Distances(i) / Prop_speed) + Size * 8/ (C *(10^9));
End_Trans_time_ONU(i) = Start_trans_time_ONU(i) + (Distances(i)/Prop_speed) + Grant_time;
aux = End_Trans_time_ONU(i) + Guard_time;
Trans_ONU = i+1;
Event_List = [Event_List; DepartureONU aux 0 0 i+1];
end
And I get the error "Undefined operator '*' for input arguments of type 'string'" on 3rd line.
Can anyone help me on solving it?
Many thanks in advance.
  댓글 수: 4
Bob Thompson
Bob Thompson 2018년 2월 6일
Ok, so what is Event_List(1,4) then? What type of array is eventlist?
Aziza Zaouga
Aziza Zaouga 2018년 2월 7일
편집: Stephen23 2018년 2월 7일
I wrote Event_List(1,4) to be a double but I figured out that I added a field which is a string. So all variables in Event_List became string. I changed that field and it worked. Anyway, many thanks for your help :)

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

채택된 답변

Jan
Jan 2018년 2월 6일
편집: Jan 2018년 2월 7일
The error message is clear: In the failing line you try to multiply a string, but this is not meaningful.
You know that the problem occurs in this line:
Start_trans_time_ONU(i) = CurrentTime + (Distances(i) / Prop_speed) + ...
Size * 8 / (C *(10^9));
Then use the debugger to find out, where the problem is: Debugger. Eitehr set a breakpoint in this line or type this in the command window:
dbstop if error
Now run the code until Matlab stops at the named line. You can examine the values of the variables, e.g.:
class(Size)
class(C)
One of them is a variable of class string and a multiplication is meaningless. Convert it to a number.
By the way: 10^9 is an expensive power operation, which is evaluated in each iteration, while 1e9 is a cheap constant.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by