Why does "[x,y,z,v] = image" result in error in MATLAB, where 'image' is a 3D matrix?

There is a predefined double-type matrix named 'flow' in MATLAB with dimensions of 25*50*25. when I want to implement this command in MATLAB:
[x,y,z,v] = flow;
It is ok and there is no problem. But, when I want to perform the same command using a similar hand-made double-type matrix with dimension of 21*101*101 , an error arises:
[x,y,z,v] = image;
Why? Why does it happen?

8 Comments

What error arises? Image() is the name of a built-in function, so if you're shadowing it with something, I can't know how exactly you're doing so.
"There is a predefined double-type matrix named 'flow' in MATLAB with dimensions of 25*50*25. when I want to implement this command in MATLAB: [x,y,z,v] = flow; It is ok and there is no problem."
Lets try it right now:
flow = rand(25,50,25);
[x,y,z,v] = flow;
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
It is not okay and there is a problem.
"Why? Why does it happen?"
Because you are trying to assign one array to four different variables... which makes no sense in MATLAB.
Hi @DGM , even if I attribute 'image' matrix to another matrix with a particular name, this error happens again:
im234 = image;
[x,y,z,v] = image;
% flow() is a demo file which generates 3D scalar fields
[x,y,z,v] = flow;
slice(x,y,z,v,5,0,0)
thank you for your answer. But, do not assign something to flow. just do this:
[x,y,z,v] = flow;
This is enough. do not include this line:
flow = rand(25,50,25);
image() is a function. If you have a matrix that you want to use, just don't call it image.
You can't reassign image() to a new name by doing this assignment:
renamedfunction = image
If you do that, the output is a handle to an image object in the current figure.
It's best to just avoid shadowing functions like that.
"But, do not assign something to flow. just do this: [x,y,z,v] = flow;"
Sure, but in that case FLOW is a function, not "a predefined double-type matrix named 'flow' in MATLAB with dimensions of 25*50*25" as you incorrectly wrote in your question. We can easily confirm that FLOW is the name of a function:
which flow -all
/MATLAB/toolbox/matlab/demos/flow.m
Calling functions with multiple outputs is shown in the introductory tutorials:
"Why? Why does it happen?"
Misunderstanding what you are working with.

Sign in to comment.

Answers (0)

Products

Release

R2018b

Asked:

on 21 Mar 2024

Commented:

on 21 Mar 2024

Community Treasure Hunt

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

Start Hunting!