Undefined Function or Variable
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Maddie Sanders
am 18 Apr. 2020
Kommentiert: Tommy
am 19 Apr. 2020
I am trying to create a function at the end of my script. I believe in my function I defined the variable ‘u.’ But then later down in the function when I try to use ‘u’ I get an error saying that ‘u’ is not defined. I am attaching an image with my code and the error. Let me know if anyone has any suggestions. Any help is appreciated.
For some reason I am having trouble submitting multiple images but I have two ‘end’s at the end of my code. Also the error message is in line 272 ‘if u==1’
0 Kommentare
Akzeptierte Antwort
Tommy
am 18 Apr. 2020
length(o) and length(n) will both be 1, as o and n are scalars, so your code never enters your for loops. You should instead use just o and n in their place. i.e.
for W = 1:o-1
5 Kommentare
Tommy
am 19 Apr. 2020
Always happy to help! Don't sweat it.
"I don't know if maybe in my u(W)=1/2/0 if I need to do u(W,K) or something like that."
If you do want to test this for all columns, then you would need a second index. Otherwise, the results of each column are being overwritten by the results of the next column. Check if u contains the expected output for the very last column in A - I believe that should be the case...
Also, are any values within A negative?
If I am understanding correctly, the point of this function is to tell the user whether values in A increase or decrease as you move down rows? Can one column increase while another column decreases?
You could simplify the process by using diff and sign. Consider these examples:
>> A = [10 20 30;40 50 60;70 80 90]
A =
10 20 30
40 50 60
70 80 90
>> sign(diff(A))
ans =
1 1 1
1 1 1
>> A = [70 80 90;40 50 60;10 20 30]
A =
70 80 90
40 50 60
10 20 30
>> sign(diff(A))
ans =
-1 -1 -1
-1 -1 -1
>> A = [10 20 30;70 80 90;40 50 60]
A =
10 20 30
70 80 90
40 50 60
>> sign(diff(A))
ans =
1 1 1
-1 -1 -1
>> A = [10 80 60;70 50 90;40 20 30]
A =
10 80 60
70 50 90
40 20 30
>> sign(diff(A))
ans =
1 -1 1
-1 -1 -1
Then it seems to me that you'd want to check if every row is increasing across every column. You might then use all. Am I on the right track?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matched Filter and Ambiguity Function finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!