Error using load Must be a string scalar or character vector
조회 수: 28 (최근 30일)
이전 댓글 표시
thanks a lot for your answer I now understand my mistake but after this when I am trying to write the rain flow script in order to reduce a spectrum of varying stress there is this error which is showing"Error using load Must be a string scalar or character vector.I am also attaching the script thanks in advance for your help.
댓글 수: 5
Harish Ramachandran
2017년 12월 20일
Is the signal in the .txt file? If so can you please attach that as well?
Jan
2017년 12월 21일
@Prateek: The code
abs(s2-s1)>=abs(s2-s3),abs(s3-s4)>=abs(s2-s3)
% ^
does not make sense. The comma means, that both parts are evaluated, but independent from each other. A simplified code:
x = 1;
y = 2;
if x == 1, y == 7
Now the condition of the IF command is "x == 1". Afterwards y is compared to 7, but this does not concern the IF in any way. Maybe you want:
if abs(s2-s1)>=abs(s2-s3) & abs(s3-s4)>=abs(s2-s3)
% or
if abs(s2-s1)>=abs(s2-s3) | abs(s3-s4)>=abs(s2-s3)
But
if abs(s2-s1)>=abs(s2-s3) , abs(s3-s4)>=abs(s2-s3)
is equivalent to:
if abs(s2-s1)>=abs(s2-s3)
답변 (2개)
Jan
2017년 12월 20일
편집: Jan
2017년 12월 20일
I am trying to extract the first four values from my signal
The symbol "load" was not defined as a variable. Then the command load() is used, but this cannot be meant. I cannot know which variable is meant, perhaps B or t? Where do you expect "load" to be defined?
Other hints:
if abs(s2-s1)>=abs(s2-s3),abs(s3-s4)>=abs(s2-s3);
What is the purpose of the part behind the comma? Perhaps you want:
if abs(s2-s1)>=abs(s2-s3) & abs(s3-s4)>=abs(s2-s3)
"sign" is a built-in function. Shadowing it by a local variable can cause serious confusion if you want to use the function later on. Avoid to use the names of important Matlab functions as local variables. See:
clear('sign')
sign(2)
sign = rand(1, 10);
sign(2)
댓글 수: 5
Jan
2017년 12월 21일
@Prateek Srivastava: There is no variable called "load" in your posted code. The error message means, that there is no such variable at all. In consequence, you cannot obtain the i.th element of this variable, because this variable does not exist at all.
Maybe you want the data of A or B?
Harish Ramachandran
2017년 12월 21일
You imported the data and stored the stress values etc. inside a struct A. s1 should get the value from the structure instead of using load command.
A=importdata('rain.txt');
This will create a struct A with A.data containing your required values.
>> A.data
ans =
1 -10
2 10
3 0
4 30
5 -20
6 0
7 -10
8 20
9 0
If you want to get the first stress value - access it by indexing through 'A.data'
s1 = A.data(1,2)
s1 =
-10
>> s2 = A.data(2,2)
s2 =
10
and so on... Hope this helps.
댓글 수: 7
Walter Roberson
2017년 12월 22일
편집: Walter Roberson
2017년 12월 22일
Your code does not assign any value to i before it uses i
Harish Ramachandran
2017년 12월 28일
Use a 'for' loop, initialize the value of i and then proceed to assignment. Or you could initialize and update the value of i accordingly in the 'while' loop.
Thank you Walter Roberson!
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!