how can i use my function directly on a array without having x and y?

2 visualizaciones (últimos 30 días)
the code is:
function img(x,y,a)
imagesc(x,y,a);
set(gca,'YDir','normal');
impixelinfo;
end
command windows:
a=rand(2,3)
a =
0.5078 0.3828 0.7304
0.3943 0.8834 0.7662
>> img(a)
Not enough input arguments.
hello guys
i am trying to creat a small function similar to imagesc by adding more option to the original imagesc function,
however i can't use my img function to a array directly
exemple, if i try to do img(a) and a= rand(2,3) i will get a error "Not enough input arguments."
any idea how can i use my function directly on a array without having x and y?

Respuesta aceptada

DGM
DGM el 14 de En. de 2022
You don't need to specify x and y when calling imagesc().
If you handle the input arguments like this:
A = imread('cameraman.tif');
img([0 1],[0 1],A)
img(A)
function img(varargin)
imagesc(varargin{:});
set(gca,'YDir','normal');
impixelinfo; % this should work fine, but won't show up in the web-figure
end
then you can call it either way.
  9 comentarios
DGM
DGM el 18 de En. de 2022
As I mentioned in the other question, I don't think that the data brush has any means of specifying which objects it selects. My attempts to disable the interaction by setting properties of the mesh object did not change the behavior. The only other alternative I could think of was to use the axes grid instead of mesh(), which carries its own problems.
Rabih Sokhen
Rabih Sokhen el 18 de En. de 2022
thank you a lot DGM !!, I really appreciate your help.
the code run perfeclty

Iniciar sesión para comentar.

Más respuestas (1)

Max Heimann
Max Heimann el 14 de En. de 2022
The function you defined has 3 arguments. x,y and a.
function img(x,y,a)
imagesc(x,y,a);
set(gca,'YDir','normal');
impixelinfo;
end
Yet you call it with just one argument "a".
a=rand(2,3)
a =
0.5078 0.3828 0.7304
0.3943 0.8834 0.7662
>> img(a)
The error message is pretty clear here. Where are the arguments x and y supposed to come from if you dont pass them as function arguments. Either somehow calculate the appropriate values in your function, hardcode them there or pass them as arguments.
  3 comentarios
Max Heimann
Max Heimann el 18 de En. de 2022
The Solution provided by DGM should do exactly that. Did you get an error when trying it?
varargin stands for Variable-length input argument list in matlab. It allows you to pass any number of arguments to your function and they will be available in the function as a cell array. You can access them with
varargin{1}, varargin{2}, ...
Or simply
varargin{:}
If you want all of the arguments at once.
In the solution provided by DGM you should be able to call your function with either a or a,x,y and the arguments will be passed to imagesc in the same order.

Iniciar sesión para comentar.

Categorías

Más información sobre Visual Exploration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by