воскресенье, 26 марта 2017 г.

Track

R=2;C=2;

vz = 10; % velocity constant
a = -32; % acceleration constant

subplot(R,C,1);

t = 0:.1:1;
z = vz*t;
% z = vz*t + 1/2*a*t.^2;

vx = 2;
x = vx*t;
%x = vx*t + 1/2*a*t.^2;

vy = 3;
y = vy*t;
% y = vy*t + 1/2*a*t.^2;

u = gradient(x);
v = gradient(y);
w = gradient(z);
scale = 0;

quiver3(x,y,z,u,v,w,scale);
view([70,18]);

subplot(R,C,2)
% z = vz*t;
z = vz*t + 1/2*a*t.^2;

vx = 2;
x = vx*t;
% x = vx*t + 1/2*a*t.^2;

vy = 3;
y = vy*t;
% y = vy*t + 1/2*a*t.^2;

u = gradient(x);
v = gradient(y);
w = gradient(z);
scale = 0;

quiver3(x,y,z,u,v,w,scale);
view([70,18]);

subplot(R,C,3)
% z = vz*t;
z = vz*t + 1/2*a*t.^2;

vx = 2;
% x = vx*t;
x = vx*t + 1/2*a*t.^2;

vy = 3;
y = vy*t;
% y = vy*t + 1/2*a*t.^2;

u = gradient(x);
v = gradient(y);
w = gradient(z);
scale = 0;

quiver3(x,y,z,u,v,w,scale);
view([70,18]);

subplot(R,C,4)
% z = vz*t;
z = vz*t + 1/2*a*t.^2;

vx = 2;
% x = vx*t;
x = vx*t + 1/2*a*t.^2;

vy = 3;
%y = vy*t;
y = vy*t + 1/2*a*t.^2;

u = gradient(x);
v = gradient(y);
w = gradient(z);
scale = 0;

quiver3(x,y,z,u,v,w,scale);
view([70,18]);

Combine Stem and Line

x = linspace(0,2*pi,60);
a = sin(x);
b = cos(x);
stem(x,a+b);

hold on
plot(x,a)
plot(x,b)
hold off

legend('a+b','a = sin(x)','b = cos(x)')
xlabel('Time in \musecs')
ylabel('Magnitude')
title('Linear Combination of Two Functions');

Include Loop Variable Value in Graph Title


x = linspace(0,10,100);
for k = 1:4
subplot(2,2,k);
yk = sin(k*x);
plot(x,yk)
title(['y = sin(' num2str(k) 'x)'])
end

Legend Mean Value + Text Signs

R=5;C=1;
dat = rand(50,1);

subplot(R,C,1);
plot(dat)
m = mean(dat);
ax = gca;
xlimits = ax.XLim;
h = line([xlimits(1),xlimits(2)],[m,m],'Color','k','LineStyle','--');

legend(h,'mean of data');

subplot(R,C,2);

g1 = hggroup;
g2 = hggroup;
t = linspace(0,2*pi,100);
plot(t,sin(t),'b','Parent',g1)
hold on
plot(t,sin(t+1/7),'b','Parent',g1)
plot(t,sin(t+2/7),'b','Parent',g1)
plot(t,sin(t+3/7),'b','Parent',g1)
plot(t,cos(t),'g','Parent',g2)
plot(t,cos(t+1/7),'g','Parent',g2)
plot(t,cos(t+2/7),'g','Parent',g2)
plot(t,cos(t+3/7),'g','Parent',g2)
hold off % reset hold state to off

legend([g1,g2],'sine','cosine')

subplot(R,C,3);
x = linspace(0,2*pi,100);
y1 = sin(x);
p1 = plot(x,y1,'DisplayName','sin(x)');
hold on
y2 = sin(x) + pi/2;
p2 = plot(x,y2,'DisplayName','sin(x) + \pi/2');
y3 = sin(x) + pi;
p3 = plot(x,y3,'DisplayName','sin(x) + \pi');
hold off

legend([p1 p2 p3])


subplot(R,C,4);

t = linspace(0,2*pi,50);
y = sin(t);
plot(t,y);

x1 = pi;
y1 = sin(pi);
str1 = '\leftarrow sin(\pi) = 0';
text(x1,y1,str1);

x2 = 3*pi/4;
y2 = sin(3*pi/4);
str2 = '\leftarrow sin(3\pi/4) = 0.71';
text(x2,y2,str2)
x3 = 5*pi/4;
y3 = sin(5*pi/4);
str3 = 'sin(5\pi/4) = -0.71 \rightarrow';

text(x3,y3,str3,'HorizontalAlignment','right');

subplot(R,C,5);

x = linspace(-3,3);
y = (x/5-x.^3).*exp(-2*x.^2);
plot(x,y);

indexmin = find(min(y) == y);
xmin = x(indexmin);
ymin = y(indexmin);
indexmax = find(max(y) == y);
xmax = x(indexmax);
ymax = y(indexmax);

strmin = ['Minimum = ',num2str(ymin)];
text(xmin,ymin,strmin,'HorizontalAlignment','left');
strmax = ['Maximum = ',num2str(ymax)];
text(xmax,ymax,strmax,'HorizontalAlignment','right');



Graph with Two y-Axes

1.
R = 5; C = 1;

subplot(R,C,1);
x = linspace(0,2*pi,25);

y1 = sin(x);
% y2 = 0.5*sin(x);
y2 = exp(-1/3*x).*sin(x);
plot(x,y1);
grid on

hold on

stem(x,y2);

hold off

subplot(R,C,2);

A = 1000;
a = 0.005;
b = 0.005;
t = 0:900;
z1 = A*exp(-a*t);
z2 = sin(b*t);

[ax,p1,p2] = plotyy(t,z1,t,z2,'semilogy','plot');
ylabel(ax(1),'Semilog Plot') % label left y-axis
ylabel(ax(2),'Linear Plot') % label right y-axis
xlabel(ax(2),'Time') % label x-axis

p1.LineStyle = '--';
p1.LineWidth = 2;
p2.LineWidth = 2;

grid(ax(1),'on')

пятница, 24 марта 2017 г.

Call .Net Methods from ML

1.
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);

webread matlab and Net classes

webRead

https://www.mathworks.com/help/matlab/ref/webread.html

Convert .NET Arrays to Cell Arrays

https://www.mathworks.com/help/matlab/matlab_external/net-arrays-to-cell-arrays.html

Pass Cell Arrays of .NET Data

https://www.mathworks.com/help/matlab/matlab_external/tips-for-working-with-cell-arrays-of-net-data.html

Handle Data Returned from .NET Objects

https://www.mathworks.com/help/matlab/matlab_external/handling-net-data-in-matlab_bte9owt-1.html#bte9paq-1

Access a Simple .NET Class

https://www.mathworks.com/help/matlab/matlab_external/access-a-simple-net-class.html

Calling .NET Methods

matlab_external/calling-net-methods.html?s_tid=gn_loc_drop

Use .NET methods in MATLAB®, method signatures, arguments by reference, optional arguments

https://www.mathworks.com/help/matlab/methods-.html