Making a 3D plot in a vectorized function
显示 更早的评论
I have a vectorized function which accepts an input vector such as:
y=myfun(x)
where
x=[x(1) x(2)]
and I want to assign vectors in x(1) and x(2) in order to make 3D plot. Do you know how can I implement this?
回答(1 个)
the cyclist
2013-2-9
Here's one way, using a cell array to hold the two vectors:
>> c = cell(1,2);
>> x = 1:10;
>> y = 1:20;
>> c{1} = x;
>> c{2} = y;
>> myfun(c)
where the file myfun.m has
function myfun(x)
[xx,yy] = meshgrid(x{1},x{2});
zz = xx + yy.^2;
figure
mesh(xx,yy,zz)
end
7 个评论
Giorgos Papakonstantinou
2013-2-9
the cyclist
2013-2-9
编辑:the cyclist
2013-2-9
Sorry, I don't understand. I do everything outside the function except defining the plotting.
Maybe you could write a little more detail on what you mean, and what you are trying to do?
Giorgos Papakonstantinou
2013-2-10
the cyclist
2013-2-10
I'm still struggling to understand both what specifically you are trying to do, and where specifically you are stuck. Would it be possible for you to post a simplified version of your code that shows what you have done and how you are stuck?
One thing that is particularly unclear to me is the size and object type that x is. You referred to it as a vector, and then as [x(1) x(2)] and then as
x(:,1)
x(:,2)
which makes it seem like a 2-dimensional array.
My advice would be to start a new question that includes your code, and is very specific about what you have done and what you can't do.
Sorry, I am sure this is partly a communication issue, and I am just not quite understanding your question.
Giorgos Papakonstantinou
2013-2-10
编辑:Giorgos Papakonstantinou
2013-2-10
the cyclist
2013-2-10
Unfortunately, I do not have the symbolic toolbox. I suggest that you take this latest comment you just made, and create a brand-new question out of it. It seems much clearer now what you are trying to do. Probably you will find some help.
Giorgos Papakonstantinou
2013-2-10
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!