.net制作调用matlab画曲线软件的实现

此为制作效果图.

目标:输入几个点的值,根据这几个点,画出点的封闭的热力学曲线图。

实现思路:1将matlab与制作的程序放到一起进行发布:缺点:安装包较大。

             2或者使用.net模拟作图

第1种:代码:m文件代码:还需要一个figure文件

function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help untitled

% Last Modified by GUIDE v2.5 28-Aug-2015 09:45:23

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to untitled (see VARARGIN)

% Choose default command line output for untitled
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% This sets up the initial plot - only do when we are invisible
% so window can get raised using untitled.
if strcmp(get(hObject,'Visible'),'off')
  %  plot(rand(5));
end

% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1);
cla;

popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
    case 1
        plot(rand(5));
    case 2
        plot(sin(1:0.01:25.99));
    case 3
        bar(1:.5:10);
    case 4
        plot(membrane);
    case 5
        surf(peaks);
end


% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% hObject    handle to FileMenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function OpenMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to OpenMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
file = uigetfile('*.fig');
if ~isequal(file, 0)
    open(file);
end

% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to PrintMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
printdlg(handles.figure1)

% --------------------------------------------------------------------
function CloseMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to CloseMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
                     ['Close ' get(handles.figure1,'Name') '...'],...
                     'Yes','No','Yes');
if strcmp(selection,'No')
    return;
end

delete(handles.figure1)


% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


%  Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
     set(hObject,'BackgroundColor','white');
end

set(hObject, 'String', {'plot(rand(5))', 'plot(sin(1:0.01:25))', 'bar(1:.5:10)', 'plot(membrane)', 'surf(peaks)'});


% --- Executes on button press in pushbutton4.
%新增一行按钮触发事件
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data = get(handles.uitable4,'data');
 [a b] = size(data);
 data(a+1,:) = {''};
 set(handles.uitable4, 'data', data);



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton5.
%计算按钮点击触发事件
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data = get(handles.uitable4,'data');
v1=str2double(data(1,1));
v2=str2double(data(2,1));
p1=str2double(data(1,2));
p2=str2double(data(2,2));
w=0;
w1=0;
q=0;
qt=0;
q1=0;
Cp=1.050;
Cv=0.762
m=Cp/Cv;
%每个节点T和T1的数量关系relCur
relCur=0.0;
%第一个节点计算及画图start
if(v1==v2)
    w1=0;
    q1=Cv*((p2/p1)-1);
    relCur=p2/p1;
    axes(handles.axes1);
    cla;
    x=0:pi/200:v1;
    plot([v1,v2],[p1,p2],'LineWidth',2);
    hold on;
else
    axes(handles.axes1);
    cla;
    n=(log10(p1)-log10(p2))/(log10(v2)-log10(v1));
    k1=p1*(v1^n);
    k2=p2*(v2^n);
    if(round(k1)==round(k2) | (k1==k2))
        if((n-1)~=0)
            q1=(n-m)/(n-1)*Cv*((v1^(n-1))/(v2^(n-1)) -1);
        else
            q1=0.287*log(v2 /v1);
        end
        relCur=(v1^(n-1))/(v2^(n-1));
        if(v1<v2)
           fun=@(v) (((v1.^n)*p1)./(v.^n));
            w1=quad(fun,v1,v2); 
           
            x=v1:pi/200:v2;
            y=k1./(x.^n);
            plot(x,y,'LineWidth',2);
           
            hold on;
           
        else
            fun=@(v) (((v2.^n)*p2)./(v.^n));
            w1=-quad(fun,v2,v1);
            x=v2:pi/200:v1;
            y=k1./(x.^n);
            plot(x,y,'LineWidth',2);
            
            hold on;
        end
        
    else
        disp('k1<>k2');
    end
    
end
q=q+q1;
if(q1>=0)
    qt=qt+q1;
end
%第一个节点计算及画图end
w=w+w1;
%遍历2-n-1个节点,进行计算及绘制曲线 end
 [a b] = size(data);
 
 i=2;
 axes(handles.axes1);

 vv2=0.0;
 
 pp2=0.0;
 while i<=a-1
     qq1=0;
     ww1=0;
     vv1=str2double(data(i,1));
     pp1=str2double(data(i,2));
     vv2=str2double(data(i+1,1));
     pp2=str2double(data(i+1,2));
     if(vv1==vv2)
        qq1=Cv*((pp2/pp1)-1)*relCur;
        relCur=relCur*(pp2/pp1);
        plot([vv1,vv2],[pp1,pp2],'LineWidth',2);
        hold on;
     else
        n=(log10(pp1)-log10(pp2))/(log10(vv2)-log10(vv1));
        kk1=pp1*(vv1^n);
        kk2=pp2*(vv2^n);
        if(round(kk1)==round(kk2) | (kk1==kk2))
            if((n-1)~=0)
                qq1=(n-m)/(n-1)*Cv*((vv1^(n-1))/(vv2^(n-1)) -1)*relCur;
            else
                qq1=0.287*log(vv2/vv1)*relCur;
            end
             relCur=relCur*((vv1^(n-1))/(vv2^(n-1)));
            if(vv1<vv2)
             fun=@(v) (((vv1.^n)*pp1)./(v.^n));
             ww1=quad(fun,vv1,vv2);
               % syms v;
             % ww1=int(((vv1^n)*pp1)/(v^n),v,vv1,vv2);
             x=vv1:pi/200:vv2;
             y=kk1./(x.^n);
             plot(x,y,'LineWidth',2);
             hold on;
            else
               fun=@(v) (((vv2.^n)*pp2)./(v.^n));
               ww1=-quad(fun,vv2,vv1);
               x=vv2:pi/200:vv1;
               y=kk1./(x.^n);
                plot(x,y,'LineWidth',2);
                hold on; 
            end
            w=w+ww1;
        else
            disp('kk1<>kk2');
        end
       
     end 
     i=i+1;
     q=q+qq1;
     if(qq1>=0)
         qt=qt+qq1;
     end
 end
 %遍历2-n-1个节点,进行计算及绘制曲线 end
 %最后一个节点的计算及绘图处理 start
 qqq1=0;
 if(vv2==v1)
     qqq1=Cv*((p1/pp2)-1)*relCur;
     plot([v1,v1],[pp2,p1],'LineWidth',2);
 else
     www1=0;
     n=(log10(pp2)-log10(p1))/(log10(v1)-log10(vv2));
     kkk1=pp2*(vv2^n);
     kkk2=p1*(v1^n);
     if(round(kkk1)==round(kkk2) | (kkk1==kkk2))
         if((n-1)~=0)
            qqq1=(n-m)/(n-1)*Cv*((vv2^(n-1))/(v1^(n-1)) -1)*relCur;
         else
            qqq1=0.287*log(v1/vv2)*relCur; 
         end
         if(vv2<v1)
             %syms v;
              %www1=int(((vv2^n)*pp2)/(v^n),v,vv2,v1);
              fun=@(v) (((vv2.^n)*pp2)./(v.^n));
             www1=quad(fun,vv2,v1);
         x=vv2:pi/200:v1;
         y=kkk1./(x.^n);
         plot(x,y,'LineWidth',2);
         else
              fun=@(v) (((v1.^n)*p1)./(v.^n));
             www1=-quad(fun,v1,vv2);
            x=v1:pi/200:vv2;
            y=kkk1./(x.^n);
            plot(x,y,'LineWidth',2); 
         end
         w=w+www1;
     else
         disp('kkk1<>kkk2');
     end
     
 end
 q=q+qqq1;
 if(qqq1>=0)
 qt=qt+qqq1;
 end
  %最后一个节点的计算及绘图处理 end
  %GUI界面赋值
  j=1;
 
  [a b] = size(data);
  maxV=0.0;
  maxP=0.0;
  while j<=a
      if(str2double(data(j,1))>maxV)
          maxV=str2double(data(j,1));
      else
      end
      if(str2double(data(j,2))>maxP)
          maxP=str2double(data(j,2));
      else
      end
      j=j+1;
  end
   xlim([0,round(maxV*1.1)]);
   ylim([0,round(maxP*1.1)]);
 set(handles.text13,'String',num2str(q/qt));
 set(handles.text11,'String',[num2str(q),'T1']);
 set(handles.text9, 'String', num2str(w));
disp('刘晓勇');


% --- Executes on button press in pushbutton6.
%删除一行按钮触发事件
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data = get(handles.uitable4,'data');
 [a b] = size(data);
 if a<=3
     
 else
     data(end,:)=[];
     set(handles.uitable4, 'data', data);
 end

  

第二种代码:C#写的,如有需求,请直接给我发邮件,邮件地址在页面footer部分。具体思路是两点之间画9999个点,这9999个点每一点x,y均符合某一热力学公式,使其成为封闭曲线。

这两种方法均做了打包,如果对安装包大小不介意,那就可以直接用matlab,代码简单。如果觉得安装包比较大,那就直接用C#模拟吧。

posted on 2016-03-15 14:26  braveliu  阅读(725)  评论(0编辑  收藏  举报

qzone: welcome to my qzone github:welcome to my github mail:contact me with gmail