現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Is it possible to have 3 or more variable inputs for a 3D contour plot in GUI?
9 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to make a 3D contour plot with an equation that has X,Y,Z and t as a variable input by the user in the GUI. Is it possible to achieve?
1 件のコメント
Basma M
2015 年 6 月 10 日
hi Bastion, i was wondering if you ever knew the correct code for this problem. i am very much interested in the solution you came up with cuz i need to solve the same equation but having difficulties doing so. I would really appreciate your feedback on this, it is somewhat urgent and i've already spent too much time and effort trying to work it out. THANKS
回答 (5 件)
Walter Roberson
2011 年 9 月 11 日
In what manner were you hoping to display your 4 dimensional data?
1 件のコメント
Bastion
2011 年 9 月 11 日
Just to clarify:
I want to make a 3D CONTOUR plot in Matlab GUI. I have an equation for Concentration (C) which is a function of (X,Y,Z,t). I'm making t as a constant. But I want the user to input the data for values of X, Y and Z.
In the Matlab help files I got this for 3D contour:
[X,Y] = meshgrid([-2:.25:2]);
Z = X.*exp(-X.^2-Y.^2);
contour3(X,Y,Z,30)
This will only allow me to input the variables for X and Y and get Z as an output. So I'm wondering if it is possible for me to let X, Y and Z be inputs and C as my output.
5 件のコメント
Walter Roberson
2011 年 9 月 12 日
According to current theory, Yes, it is possible, if you have a spinning negatively charged black hole and you can enter its outer "naked singularity" without touching its event horizon. However, theory has not yet determined whether it would ever be possible to re-enter *this* Universe afterwards, partly because the concept of "afterwards" would have little meaning once you had managed to complete the trade of time for another spacial dimension in order to be able to construct the graph with 4 spacial dimensions.
See http://www.mathworks.com/matlabcentral/answers/11433-plotting-3d-of-output
Bastion
2011 年 9 月 12 日
Ok so it is practically impossible, thanx for the replies, I have to use contour. I guess I will just make 3 different contours, C(X,Y) C(X,Z) and C(Y,Z)
Walter Roberson
2011 年 9 月 12 日
You might also consider isosurface() or slice().
Also, some people have indicated that the scatter3() solution I proposed in the linked question has been fine for their needs. Representing a contour in that method might be a bit tricky, though.
Bastion
2011 年 9 月 12 日
yeah I'm looking at isosurface but can't seem to place equation, I'll check it out
Dmitry Borovoy
2011 年 9 月 12 日
If you really need to use function just create your own shell-function.
function MyContour3(X,Y,Z,t)
% add logic for assigning t in your equation
contour3(X,Y,Z)
end
26 件のコメント
Dmitry Borovoy
2011 年 9 月 12 日
I don't know what change when GUI is used. I understood that you need 3D contour. But for some reasons you need function that uses 4 input variable where first 3 variables is a simple coordinats and fourth is time that is constant for current moment. Is it correct? So just create your function as I show before
Walter Roberson
2011 年 9 月 12 日
Dmitry, you missed that Bastion needs X, Y, and Z to calculate C (concentration), and thus is trying to do 4 dimensional display: a distance along X to represent the X coordinate, a distance along Y to represent the Y coordinate, a distance along Z to represent the Z coordinate -- but then how do you do the distance along C to represent the resulting value?
Bastion
2011 年 9 月 12 日
If I input all the values for X,Y,Z and I join them together wouldn't that give me a contour?
Walter Roberson
2011 年 9 月 12 日
Do you mean all of the values that give you a specific concentration? If so that would be an isosurface rather than a contour. I suppose you could do multiple isosurface plots in the same axes, but I am not at all sure that you would be able to make any sense out of the result.
Bastion
2011 年 9 月 12 日
It's alright I've decided to just try with C(X,Y) etc.
but can you help me with this code?
------------------------------------------------------------------------
X = str2double(get(handles.Input_3D_x,'String'));%%%%% user inputs X
Y = str2double(get(handles.Input_3D_y,'String'));%%%%% user inputs Y
Z = str2double(get(handles.Input_3D_z,'String'));%%%%% user inputs Z
t = str2double(get(handles.Input_t,'String'));%%%%% user inputs t
[X,Y] = meshgrid(-10:0.25:10); %%%%% this part I'm not too sure of
C = X.*Y.*Z.*t %%%%% The equation that operates the user inputs
contour3(X,Y,C,100) %%%%% ploting a contour of C in the Z-axis with X and Y in their respective axis
------------------------------------------------------------------------
I get a squiggly orange line for X and Y in the first 2 lines, and it says: "The value assigned to varaible 'X' might be unused." ditto for Y.
If I input any variables for X or Y the contour doesn't change. I'm thinking I'm made an error somewhere.
Bastion
2011 年 9 月 12 日
If I put "C = X.*Y.*Z.*t" above "[X,Y] = meshgrid(-10:0.25:10);" then the equation doesn't work
Walter Roberson
2011 年 9 月 12 日
What format are you expecting the user to have entered data in to Input_3D_x and so on? Are they to be the X, Y, and Z ranges? If so are you expecting a pair of numbers or are you expecting a single number that you will use as the positive and negative bounds?
Try
Xmax = str2double(get(handles.Input_3D_x,'String'));%%%%% user inputs X
Ymax = str2double(get(handles.Input_3D_y,'String'));%%%%% user inputs Y
Zmax = str2double(get(handles.Input_3D_z,'String'));%%%%% user inputs Z
t = str2double(get(handles.Input_t,'String'));%%%%% user inputs t
[X,Y,Z] = ndgrid(-Xmax:0.25:Xmax, -Ymax:0.25:Ymax, -Zmax:0.25:Zmax);
C = X.*Y.*Z.*t %%%%% The equation that operates the user inputs
But now you have a problem, in that X, Y, and Z are now 3 dimensional arrays. When you talk about contour3(X,Y,C,100) you are implicitly wanting to project along an axes, but C will have multiple values along that axes for each (x,y) position. You need to resolve this.
One resolution that _sometimes_ makes sense is to take the maximum (or minimum) value along the axes. So, for example,
contour3(X(:,:,1), Y(:,:,1), max(C,[],3), 100)
Bastion
2011 年 9 月 12 日
Hey thanx for the reply, all of the user inputs are one value;
I was searching here and came across this:
http://www.mathworks.com.au/matlabcentral/answers/15558-plot-a-6x6-matrix-in-3d
"N=6;
[X,Y]=meshgrid(1:N,1:N);
surf(X,Y,A);"
Like the range is 1:X, so the users only have to input one number. Like a matrix thing, I tried that in my code but it doesn't work.
I'll try your one now and I'll get back to ya.
Bastion
2011 年 9 月 12 日
Hey I tried it, it works, but I think there is some error, I keep hearing the 'ding' sound. Also I'm not quite sure what you did there, an explanation would be good.
Walter Roberson
2011 年 9 月 12 日
At the command window, put in the command
dbstop if error
and then run the program. It will stop at the line that is causing the problem and tell you the kind of problem it is encountering. You can examine the variable sizes and classes and values to try to determine the source of the problem.
It is difficult for us to debug problems without knowing which line was the problem and what the error message was.
Walter Roberson
2011 年 9 月 12 日
I used Xmax and Ymax and Zmax all equal, with code I showed above that ends in the contour3 call. It seemed to work fine considering the limitations of having to project C down to 3D.
I also used
scatter3(X(:),Y(:),Z(:),10,C(:))
colormap(hsv)
and that produced something somewhat intelligible, though not contoured.
The biggest problems with the two tests above was that the mesh was too coarse to produce a good-looking plot over the range -5:+5 .
I refined the mesh to steps of 1/64 . That slowed things down a fair bit, matrix sizes 641 x 641 x 641
I then
Cmin = min(C(:));
Cmax = max(C(:));
[n,bin] = histc(C(:),linspace(Cmin,Cmax,11));
scatter3(X(:),Y(:),Z(:),10,bin)
Plotting with those array sizes was notably slow. The above is akin to doing a contour plot with (11-1) = 10 levels (the 11th level will exist in there but will be only the 4 peaks of the symmetric C calculation.) Did I mention this was notably slow? :( A few hundred million points to plot... Guess I might as well go sign in the after-hours log while I am waiting for it to finish...
Walter Roberson
2011 年 9 月 13 日
The above was just too slow with the grid step of 1/64 over -5:+5 .
Referring to the above variables, I then used
u = unique(round(rand(1,floor(length(bin)/1000))*length(bin)));
scatter3(X(u),Y(u),Z(u),10,bin(u))
That was still somewhat slow but at least it could be worked with. It did not produce surfaces as would be hoped for contours, but it was still useful in showing the different value levels (several simultaneously)
I also used
p = patch(isosurface(X,Y,Z,C,100));
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
daspect([1 1 1])
view(3)
camlight; lighting phong
That was a fairly reasonable time-frame and produced smooth surfaces for the one value level (100) that had been specified.
The examples in isosurface() show calls to isonormal() . That took at notable time and then failed trying to interp3. My speculation is that it ran out of memory or something similar, though the complaint it gave was that the coordinates had not been produced by meshgrid (producing them by ndgrid should have done fine.)
Bastion
2011 年 9 月 13 日
My computer won't handle it if there's too many points to plot
Yeah I'm going to try the:
u = unique(round(rand(1,floor(length(bin)/1000))*length(bin)));
scatter3(X(u),Y(u),Z(u),10,bin(u))
p = patch(isosurface(X,Y,Z,C,100));
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
daspect([1 1 1])
view(3)
camlight; lighting phong
Thanx for the answers, I'll let you know how it goes
Walter Roberson
2011 年 9 月 13 日
I'm not sure you would want to use both scatter3() and patch(), but it might make sense to do so if you had a particular level you needed emphasized (via the patch) and wanted to get an idea of how the others were distributed (via the scatter3).
The scatter3() part was much slower than the construction of the isosurface, so if the isosurface gives you what you need, you will probably want to skip the scatter3()
Hmmm, you might want to add a max() of the floor(length(bin)/1000) and some minimum number of points, in case the initial size of the mesh is very small -- you don't want to end up with u being empty or only having 1 point for example.
Walter Roberson
2011 年 9 月 13 日
The 1 in 1000 sampling I did in constructing u was related to when I was using 1/64 as the step size instead of the 1/4 that you originally coded; depending on the input ranges you specified, the 1 in 1000 random sampling might have been too small to be useful.
Bastion
2011 年 9 月 13 日
Sorry I'm confused at where you mentioned isosurface? I did not see this part
I'm not very versed in Matlab GUI at all, let alone Matlab so some of your statements are not really registering.
Bastion
2011 年 9 月 13 日
I went back to the first equation that you suggested:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M = str2double(get(handles.Input_M,'String'));
n = str2double(get(handles.Input_n,'String'));
Vx = str2double(get(handles.Input_Vx,'String'));
Dx = str2double(get(handles.Input_Dx,'String'));
Dy = str2double(get(handles.Input_Dy,'String'));
Dz = str2double(get(handles.Input_Dz,'String'));
Xmax = str2double(get(handles.Input_3D_x,'String'));
Ymax = str2double(get(handles.Input_3D_y,'String'));
Zmax = str2double(get(handles.Input_3D_z,'String'));
t = str2double(get(handles.Input_t,'String'));
[X,Y,Z] = ndgrid(-Xmax:0.25:Xmax, -Ymax:0.25:Ymax, -Zmax:0.25:Zmax);
C = ((M./n)./(8).*((3.14.*t).^1.5).*sqrt(Dx.*Dy.*Dz)).*exp((-((X-Vx.*t).^2)./4.*Dx.*t)-(Y.^2/4.*Dy.*t)-(Z.^2./4.*Dz.*t));
contour3(X(:,:,1), Y(:,:,1), max(C,[],3), 100)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This works the best and produces something similar and allows the user to set boundaries. Do you think it's reasonable? Or explore isosurface?
Walter Roberson
2011 年 9 月 16 日
Looks to me like you would get a divide by zero error if any of the Dx, Dy, or Dz were zero, and that you would get a complex result if an odd number of them were negative or if t is negative.
Question: does 3.14 represent Pi ?
Bastion
2011 年 9 月 17 日
Yeah 3.14 is pi, not sure of the notation in Matlab yet.
Ummmm If i change any of the variable inputs it will change the contour HOWEVER this is not true for Xmax and Ymax as both does not change the contour no matter what value I input
Walter Roberson
2011 年 9 月 20 日
The MATLAB notation for pi is pi
Test values would help so that I do not end up looking at a different oddity than you are looking at.
Bastion
2011 年 9 月 22 日
Thanx for helping,
M=10
n=1
Vx=1
Dx=1
Dy=1
Dz=1
Xmax=2
Ymax=2
Zmax=2
t=10
would be fine
at the moment the graph doesn't change when I change the Xmax and Ymax input when I plot contour3(X,Y,C). But if I change any of the other variables the graph changes.
Sean de Wolski
2011 年 9 月 12 日
An isosurface with different colored and shaded patch es can be used to visualize 4d data.
doc isosurface
doc patch
1 件のコメント
Basma M
2015 年 6 月 10 日
hi Bastion, i was wondering if you ever knew the correct code for this problem. i am very much interested in the solution you came up with cuz i need to solve the same equation but having difficulties doing so. I would really appreciate your feedback on this, it is somewhat urgent and i've already spent too much time and effort trying to work it out. THANKS
1 件のコメント
Walter Roberson
2015 年 6 月 11 日
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)