вторник, 28 марта 2017 г.

Simple graphics examples for Matlab 3D

1. Elefant
[x,y,z] = meshgrid(-2:0.1:2);
F=(x.^2 + y.^2 + z.^2) - 3;
isosurface(x,y,z,F,0);
 F=(x.^3 + y.^3 + z.^3) -2;
 isosurface(x,y,z,F,0);
 axis auto
 axis([-3, +3 , -3, +3, -3, +3]);

2. 
[x,y,z] = meshgrid(-2:0.1:2); 
 F=x.^2 + y.^2 + z.^2 -3;
 isosurface(x,y,z,F,0);
 F=x.^2 + y.^3 + z.^2 -3;
 isosurface(x,y,z,F,0);
 F=x.^2 + y.^3 + z.^2 +3;
 isosurface(x,y,z,F,0); 
 axis([-2.5, +2.5 , -2.5, +2.5,-2.5, +2.5]);

 % axis auto

3.
clc
[x,y,z] = meshgrid(-2:0.1:2);  
F=x.^4 + y.^4 + z.^4 - (x.^2 + y.^2 + z.^2); 
% surface(x,y,z,F,0)
% isosurface(x,y,z,F,0)
 hpatch = patch(isosurface(x,y,z,F,0)); 
 isonormals(x,y,z,F,hpatch); %посчитаем нормали для красоты
 set(hpatch,'FaceColor','r','EdgeColor','none'); %немного цвета для красоты

 camlight left; lighting phong; %немного света для красоты



Simple graphics examples for Matlab

1.
N = 50;

NgrStr = 6;
NgrColumn = 1;

y1 = randn(N,1);

stat.mean = mean(y);
stat.std = std(y);
stat.median = median(y);

y2 = filter([ 1 1]/2,1,y);

t = linspace(0, 0.01, N);

subplot(NgrStr,NgrColumn,1);

plot(t,y1);
grid on;

subplot(NgrStr,NgrColumn,2);

plot(t,y2);
grid on;

subplot(NgrStr,1,3);
plot(y,'DisplayName','y');hold on;plot(y2,'DisplayName','y2');hold off;
grid on;

subplot(NgrStr,NgrColumn,4);

plot(y1,y2);
grid on;

subplot(NgrStr,NgrColumn,5);
stem(y2-y1);
grid on;

subplot(NgrStr,NgrColumn,6);
hist(y2-y1);
grid on;

.Net Assembly from MatLab

.Net Assembly from MatLab

1.
NET.addAssembly('System.Speech');
ss = System.Speech.Synthesis.SpeechSynthesizer;
ss.Volume = 100;
Speak(ss,'You can use .NET Library in Matrix Laboratory');

2.
asmpath = 'D:\VC\1305\gs.trade\GS.Matlab\bin\Debug\';
asmname = 'GS.Matlab.dll';

asm = NET.addAssembly(fullfile(asmpath,asmname));

obj = GS.Matlab.MyGraph;

mlData = cell(obj.getNewData)
objArr = cell(obj.getObjectArray);

objNewDataArr = obj.getNewDataProp;

figure('Name',char(mlData{1}))
plot(double(mlData{2}(2)))

xlabel(char(mlData{2}(1)))

3.
% F:\Work\Math\Matlab\Net
% NetDocCell_01.m

R = 3;
C=1;
asmpath = 'D:\VC\1305\gs.trade\GS.Matlab\bin\Debug\';
asmname = 'GS.Matlab.dll';

asm = NET.addAssembly(fullfile(asmpath,asmname));

obj = GS.Matlab.MyGraph;

mlData = cell(obj.getNewData);
%objArr = cell(obj.getObjectArray);
objNewDataArr = obj.getNewDataProp;

figure('Name',char(mlData{1}));
subplot(R,C,1);
% figure('Name',char(mlData{1}));
plot(double(mlData{2}(2)));
xlabel(char(mlData{2}(1)));

subplot(R,C,2);
objArr = obj.getObjectArray();

doubles1 = double(objArr(1));
doubles2 = double(objArr(2));

plot([doubles1 doubles2]);

subplot(R,C,3);
objDouble = obj.getDoubleArray;
doubles = double(objDouble);

plot(doubles);

------------------------------------------------------------

.cs
D:\VC\1305\gs.trade\GS.MAtlab\
namespace GS.Matlab
{
    // Call Methods from .Net Assembly from Matlab 
    public class MyGraph
    {
        public Object[] getNewData()
            /*
         * Create a System.Object array to use in MATLAB examples.
         * Returns containerArr System.Object array containing:
         *  fLabel System.String object
         *  plotData System.Object array containing:
         *      xLabel System.String object
         *      doubleArr System.Double array
        */
        {
            String fLabel = "Figure Showing New Graph Data";
            Double[] doubleArr =
            {
                18, 32, 3.133, 44, -9.9, -13, 33.03
            };
            String xLabel = "X-Axis Label";
            Object[] plotData = {xLabel, doubleArr};
            Object[] containerArr = {fLabel, plotData};
            return containerArr;
        }

        public Object[] getNewDataProp {
        get
        {
            String fLabel = "Figure Showing New Graph Data";
            Double[] doubleArr =
            {
                18, 32, 3.133, 44, -9.9, -13, 33.03
            };
            String xLabel = "X-Axis Label";
            Object[] plotData = {xLabel, doubleArr};
            Object[] containerArr = {fLabel, plotData};
            return containerArr;
        }
        }

    public object[] getObjectArray()
        {
            var arr1 = new double[] {1, 2, 3, 4, 5};
            var arr2 = new double[] { 6, 7, 8, 9, 10 };
            return new object[] {arr1, arr2};
        }
        public double[] getDoubleArray()
        {
            return new double[] { 1, 2, 3, 4, 5 };
        }

        public object[] getObjectArrayProp => new object[]
        {
            new double[] {1,2,3},
            new double[] {4,5,6,7,8,9}
        };
        public double[] getDoubleArrayProp => new double[] { 1, 2, 3, 4, 5 };
    }

}

MCR MPS