Why histeq in Matlab is not working - matlab

I want equalize an image histogram. I tried the following code:
I = imread('1.png');
greyI = rgb2gray( I(:,:,1:3) );
J = histeq( greyI );
But the following warning occurred:
??? Attempt to execute SCRIPT histeq as a function:
D:\MatLab Prog\histeq.m
Error in ==> histeq at 3
J = histeq( greyI );
I also tried to get help from about histeq function, but that returns
No help found for histeq.m.
Help from you would be appreciated.

You have created your own file called histeq, see the error message. Delete or rename it to resolve the program.

Related

Simulink adding blocks

Trying to use simulink but have some problems:
part.type = 'PB1';
part.name = ['SLibrary/PB_1_' int2str(rjoint1Count) '_Default/PB1_1' ];
part.handle = add_block(pjnt11, [sys '/' part.name], 'Position', pos, 'MakeNameUnique', 'on');
where
pjnt11 = 'SLibrary/PB_1_Default/PB1_1 ';
sys=Robot
which are defined before. Also the predefined SLibrary/PB_1_Default/PB1_1is
and
When I run the code I got the following error:
Error using startSimulation (line 134)
A new block named 'Robot/SLibrary/PB_1_1_Default/PB1_1' cannot be added
Tried to find it online but couldn't find any solution.
Thanks in advance.
You are trying to add a block, giving it the same name as an existing block. Block's must have unique names.

MATLAB Optimization toolbox example

https://www.mathworks.com/help/optim/examples/banana-function-minimization.html
fun = #(x)(100*(x(2) - x(1)^2)^2 + (1 - x(1))^2);
options = optimset('OutputFcn',#bananaout,'Display','off');
x0 = [-1.9,2];
[x,fval,eflag,output] = fminsearch(fun,x0,options);
title 'Rosenbrock solution via fminsearch'
Fcount = output.funcCount;
disp(['Number of function evaluations for fminsearch was ',num2str(Fcount)])
disp(['Number of solver iterations for fminsearch was ',num2str(output.iterations)])
What is #bananaout here?
This is giving me the following error,
??? Error using ==> feval
Attempt to execute SCRIPT bananaout as a function:
C:\Users\admin\Desktop\bananaout.m
Error in ==> callAllOptimOutputFcns at 12
stop(i) = feval(OutputFcn{i},xOutputfcn,optimValues,state,varargin{:});
Error in ==> fminsearch>callOutputAndPlotFcns at 464
stop = callAllOptimOutputFcns(outputfcn,xOutputfcn,optimValues,state,varargin{:})
|| stop;
Error in ==> fminsearch at 199
[xOutputfcn, optimValues, stop] =
callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'init',itercount, ...
Error in ==> test_optim at 9
[x,fval,eflag,output] = fminsearch(fun,x0,options)
As per the doc, Output Functions are called by the optimizer at every time step, enabling you to do things like plot the progress of the optimization.
In your case you get an error because bananaout seems to be a script when it needs to be a function (with specific inputs - see the doc for their details). Did you happen to save the example code in a script called bananaout? If so, rename the script.
You can see a list of all m-code that you have that are called bananaout by executing the following:
>> which bananaout -all
One of them will be the function that the example should be calling, while another will be the one that you have created and need to rename/remove.

Cannot create output file with saveas

i wrote that code
clear all;
clc;
addpath('C:\Users\John\Documents\MATLAB\code for yannis\anger(W)\');
h1 = dir('C:\Users\John\Documents\MATLAB\code for yannis\anger(W)\');
for i=3:numel(h1)
%disp(h1(i,1).name);
%disp(k);
three(h1(i,1).name);
end
and the three function is
function three(filename)
%disp(filename);
q = char(39);
filename = strcat(q,filename,q)
%disp(filename);
load(filename);
And i get that error:
Error using load
Unable to read file '03a01WaM.mat': No such file or directory.
Error in three (line 7)
load(filename);
Error in run_three (line 13)
three(h1(i,1).name);
i also wrote exist('03a01WaM.mat') and the function return 2
Does anyone has an idea, what am i doing wrong?
There are multiple issues with your code.
addpath is simply unnessecary.
You are using relative path, but not cd. You have to use the full path to access the files.
You are adding a apostrophe to the filename.
Correct code would be:
directory='C:\Users\John\Documents\MATLAB\code for yannis\anger(W)\'; %'
h1 = dir(directory);
for i=3:numel(h1)
filename=fullfile(directory,h1(i,1).name);
load(filename);
end

passing image to a matlab function

i have a function
function[a,b,c] = segmentimage(image)
i am not able to give the image 'bird.png' to this function.
i get an error if i write
segmentimage('bird.png')
as
Error: File: segmentimage.m Line 27 Column: 66
if i declare
image= imread(bird.png)
before the function declaration, then also i am getting an error
Function definitions are not permitted at the prompt or in scripts.
please help. thanks in advance
In option 2 I think you're doing something like this in your script,
image= imread(bird.png)
function[a,b,c] = segmentimage(image)
First of all, you should have
image = imread('bird.png');
and you should not declare anything in the function script, so, erase the first line.
it should be,
function[a,b,c] = segmentimage(image)
%your code here,
im = imread(image);
%a = ...
%b = ...
%c = ...
end
then you can call your function in another script,
[a, b, c] = segmentimage('bird.png');
About the first error, you have to post some code, especially the line in which the error occurs so we can help.

eval( MPI_Run( MPI_cc('xbasic'), 2,machines) ) gives me error

I want to use mpiMatlab for my algorithm,i have problem in INSTALLING AND RUNNING of it.
According to this link can any one help me:
http://www.ll.mit.edu/mission/isr/matlabmpi/matlabmpi.html
when i wrote this command in matlab:
eval( MPI_Run( MPI_cc('xbasic'), 2,machines) );
It gives me this error:
??? Undefined function or
method 'MPI_cc' for input
arguments of type 'char'.
Error in ==> Untitled at 1
eval( MPI_Run(
MPI_cc('xbasic'), 2,machines)
);
The error messages suggests that the source code folder is not defined in your MATLABPATH.
Try
which MPI_cc
To see if you can see the code.
Then try to walk before you run.
Does this work?
eval( MPI_Run('xbasic', 2,machines) );
Next does this work?
MPI_cc('xbasic');
Once all these steps are working then you can try your original code.
eval( MPI_Run( MPI_cc('xbasic'), 2,machines) );