??? Error: File: min_max.m Line: 3 Column: 32 Unexpected MATLAB operator.

1 visualizzazione (ultimi 30 giorni)
Hi, i want to read a image file using function , and i have just written following 3 lines
what is the reason to show the error
function [min,max]= imread(moon.jpg)
ima=imread(moon.jpg); % reads in image
% display image
imshow(ima);
error is : ??? Error: File: min_max.m Line: 3 Column: 32 Unexpected MATLAB operator.

Risposta accettata

Image Analyst
Image Analyst il 26 Ago 2013
This is a function declaration so you do not list actual argument values in the argument list when you are declaring your function. You use variable names and then pass in the actual values later, when you call it, not when you declare it. Also, don't use min, max, and imread for names of functions or variables since they are reserved built-in names. Do it this way:
function [minValue, maxValue] = my_imread(filename)
minValue = -1; % Initialize
maxValue = -1;
if exist(filename, 'file')
grayImage = imread(filename); % reads in image
% display image
imshow(grayImage);
minValue = min(grayImage(:));
maxValue = max(grayImage(:));
else
errorMessage = sprintf('Error %s does not exist!', filename);
uiwait(warndlg(errorMessage));
end
Then call it
[minValue, maxValue] = my_imread('moon.jpg')
  1 Commento
Varun Keshavan Bhaskara
Varun Keshavan Bhaskara il 11 Apr 2018
Modificato: Varun Keshavan Bhaskara il 11 Apr 2018
hey can you help me out with this projectile motion,, it says
" File: OpenANewFileExample.m Line: 21 Column: 19 Unexpected MATLAB expression."
My code is,
%% projectilemotion
clc
% pm_parameters
% constants
m1=0.15; %kg
m2=0.18; %kg
e=1.5; %mpa
h=1.8; %m
l=0.6;%m
deltal=0.16; %m
r=100; %m
g = 9.81; %m/s^2
theta=45*pi/180; %rad
function[C,Ceq]=pm_nlconst(x)
a=x(1);
v0=x(2);
d=sqrt((v0*v0*m2*4l)/(deltal*deltal*pi*e));
c1 = (sqrt((deltal^2*k*0.5*2)/(m2)))/v0;
c2=((pi*d*d)/4)/a;
C=[c1,c2];
Ceq=[];
end
function[out] = pm(x)
a=x(1);
v0=(x2);
out= ((pi*d*d*e*deltal)/(4*l*0.33));
end

Accedi per commentare.

Più risposte (2)

Azzi Abdelmalek
Azzi Abdelmalek il 26 Ago 2013
Modificato: Azzi Abdelmalek il 26 Ago 2013
Use
im=imread('moon.jpg')
Do not use min and max as variables (they are Matlab functions). The same remark for your function name:
For example write
function [min1,max1]= image_read(moon.jpg)
ima=imread('moon.jpg'); % reads in image
% display image
imshow(ima);
% your code

Uni Lübeck
Uni Lübeck il 27 Ago 2013
Hey thank you very for your answer. its really helpful.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by