Error in OCTAVE code

Asked

Viewed 251 times

0

I just started programming on OCTAVE and my code presented the following error:

Código da função

Commands and function call

>> A = imread('cameraman.tif');
>> B = imread('circuit.tif');
>> D = sub_img(A,B);

Error:

Warning: Suggest parenthesis Around assignment used as Truth value near line 4, column 15 in file 'C: Users rafae Octave 0-intro-Matlab-Octave sub_img. m'

error: in computed assignment A(index) OP= X, A must be defined first

error: called from sub_img at line 4 column 3

With this, I tried other sources of research to find the solution, but none served me. I appreciate the attention

2 answers

1

Good after the help of ederwander. I was able to reach other solutions and manages to leave the code "correct" at first.

After the correction made the code printed what was to be printed 'images are not the same size'. However, another error appeared: value on right hand side of assignment is Undefined. To correct it it was necessary to put a value for the variable C (C = 0) the function C = sub_img(A,B). Thus the code of the function was left:

Código alterado

Then, after using it he sent the message, but I realized that the code would never leave the if because the <= condition would always be true, so I just left <. And for the 'Else' to work, i made a script that changes the size of image B to equal the size of image A and thus show the image with the pixels replaced.

Script (Note that the script has a different task than the function, I just took advantage of even the resize command):

clear; %Clean the variables

A = imread('cameraman.tif'); % Read the first image

B = imread('Circuit.tif'); % Read the second image

imshow(A); pause(3); %Display the first image and wait 3 seconds imshow(B); pause(3); %Show the second image and wait 3 seconds

B = imresize(B, size(A)); %Changes image size B to image size A

C = imadd(A,B); imshow(C); %Shows the sum 8 Bits

Duas imagens com seus pixels subtraidos

Well, at first my problem was solved, and I would like to ask that if anyone has any book, source, archive to indicate to study programming in Ctave I thank you.

Thank you Ederwander!

0

I think there is a syntax error in your function, there is no or I at least have never seen this type of operator in Octave/Matlab -= I think you want to compare if the dimensions of A and B are equal then you should use the operator ==, the first Warning that appeared in your code was because you did not add more parentheses in your if follows a simple test with the above observations running on the Octave without errors:

A = [1 2 3]
B = [1 2 3]
if ((size(A) == size(B)))
    disp("oi")
end
  • Actually, after what you wrote I researched a little better and -= doesn’t exist, the right one would be <=. Probably, as I am using an "old" book, the nomenclature used in it no longer exists. Would you happen to have any nomenclature? Also, with what you have spoken I will post the solution response and the changes I have made :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.