The following MatLab code I am using to plot the graph:
path1 = '/DATA/sanjay/VT-GAN-master/new_Results_for_diverse_features/nm_to_nm/';
list1 = dir(path1);
fName1 = {list1.name};
[~,y1]=size(fName1);
path1
vector = [];
title = {'000','018','036','054','072','090','108','126','144','162','180'};
title = categorical(title);
x_axis = {'01','02','03','04','05','06','07','08','09','10'};
x_axis = categorical(x_axis);
mat1 = [];
for num1=3:y1
path2 = char(strcat(path1,fName1(num1)));
data = readtable(path2);
data = data{:,:};
mat1 = [mat1;mean(data)];
end
mat1
data01 = mat1(:,1);
data02 = mat1(:,2);
data03 = mat1(:,3);
data04 = mat1(:,4);
data05 = mat1(:,5);
data06 = mat1(:,6);
data07 = mat1(:,7);
data08 = mat1(:,8);
data09 = mat1(:,9);
data10 = mat1(:,10);
data11 = mat1(:,11);
figure,
plot(x_axis,data01,'-+',x_axis,data02,'-*',x_axis,data03,'-o',x_axis,data04,'-x',x_axis,data05,'-s',x_axis,data06,'-d',x_axis,data07,'-p',x_axis,data08,'-h',x_axis,data09,'-^',x_axis,data10,'->',x_axis,data11,'-<','linewidth',2,'MarkerSize',12);
xlim([1 10])
lgd = legend('Probe angle: 000','Probe angle: 018','Probe angle: 036','Probe angle: 054','Probe angle: 072','Probe angle: 090','Probe angle: 108','Probe angle: 126','Probe angle: 144', 'Probe angle: 162','Probe angle: 180');
lgd.FontSize = 18;
lbx = xlabel('Rank from one to ten for nm to nm gallery and probe set','fontname','times');
lby = ylabel('Average accuracy in percentage (%)','fontname','times') ;
lbx.FontSize = 18;
lby.FontSize = 18;
set(gca,'FontWeight','bold')
But I am getting the following error because of xlim:
Error using xlim (line 31)
Value must be a 2-element vector of increasing or equal categorical values as ordered by the ruler Categories property.
Error in Rank_based_Curv (line 34)
xlim([1 10])
how do I limit the index from 01 to 10 and remove the extra parts from both sides on the X axis?
Related
I have a code where I am taking x1, y1, z1 and the radius d as inputs from the user. In my callback function, I am reading these values and I have to plot a 3D circle in MATLAB's App Designer. How can I do so? I have a code for plotting a point in 2D but the same thing is not working when I am trying for a 3D plot.
x1 = app.NumericEditField.Value;
y1 = app.NumericEditField4.Value;
z1 = app.NumericEditField7.Value;
plot(app.UIAxes,x1,y1,'o'); %Code for a point in 2D plot.
grid(app.UIAxes,'on');
Plotting Circles and Spheres on UIAxes
A circle can be plotted in MATLAB app-designer by using the plot3() function. Sin() and cos() can then be used to get a set number of (x,y) points which can be stored in a matrix. Another matrix of the same size which stores the (z) points must also be created.
In short 3 vectors for the x,y,z points and plot3() are required. I also included a sphere just in case.
app = uifigure();
app.Color = '#FFFFFF';
Field_Height = 20;
Field_Width = 80;
%Creating input text field for x1%
x1 = uieditfield(app,'numeric');
x1.Position = [10 100 Field_Width Field_Height];
x1_Label = uilabel(app);
x1_Label.Text = 'x1';
x1_Label.Position = [100 100 Field_Width Field_Height];
%Creating input text field for y1%
y1 = uieditfield(app,'numeric');
y1.Position = [10 70 Field_Width Field_Height];
y1_Label = uilabel(app);
y1_Label.Text = 'y1';
y1_Label.Position = [100 70 Field_Width Field_Height];
%Creating input text field for z1%
z1 = uieditfield(app,'numeric');
z1.Position = [10 40 Field_Width Field_Height];
z1_Label = uilabel(app);
z1_Label.Text = 'z1';
z1_Label.Position = [100 40 Field_Width Field_Height];
%Creating input text field for the radius%
Radius = uieditfield(app,'numeric');
Radius.Position = [10 10 Field_Width Field_Height];
Radius_Label = uilabel(app);
Radius_Label.Text = 'Radius';
Radius_Label.Position = [100 10 Field_Width Field_Height];
%Creating 3D axes%
Axes_3D = uiaxes(app);
Axes_3D.Position = [150 20 400 400];
plot3(Axes_3D,0,0,0,'Color','b');
Axes_3D.XGrid = 'on';
Axes_3D.YGrid = 'on';
Axes_3D.ZGrid = 'on';
Axes_3D.XLabel.String = "x axis";
Axes_3D.YLabel.String = "y axis";
Axes_3D.ZLabel.String = "z axis";
Axes_3D.BackgroundColor = '#FFFFFF';
%Setting callback functions for each input field%
x1.ValueChangedFcn = #(x1,event) Plot_Sphere(x1,y1,z1,Radius,Axes_3D);
y1.ValueChangedFcn = #(y1,event) Plot_Sphere(x1,y1,z1,Radius,Axes_3D);
z1.ValueChangedFcn = #(z1,event) Plot_Sphere(x1,y1,z1,Radius,Axes_3D);
Radius.ValueChangedFcn = #(Radius,event) Plot_Sphere(x1,y1,z1,Radius,Axes_3D);
%Function that gets called when any input field is changed%
function [] = Plot_Sphere(X_Field,Y_Field,Z_Field,Radius_Field,Axes_3D)
%Grab the positions.offsets from each field%
X_Position = X_Field.Value;
Y_Position = Y_Field.Value;
Z_Position = Z_Field.Value;
Radius = Radius_Field.Value;
%Creating a matrix of points for the sphere%
[X_Base,Y_Base,Z_Base] = sphere;
%Multiplying the points depending on a given radius%
X = X_Base * Radius;
Y = Y_Base * Radius;
Z = Z_Base * Radius;
%Creating a matrix of points for the circle%
Number_Of_Data_Points = 200;
theta = linspace(0,2*pi,Number_Of_Data_Points);
X_Circle = Radius*cos(theta);
Y_Circle = Radius*sin(theta);
Z_Circle = zeros(1,Number_Of_Data_Points);
%Plotting the circle%
plot3(Axes_3D,X_Circle+X_Position,Y_Circle+Y_Position,Z_Circle+Z_Position);
%Switch this line to get sphere%
% plot3(Axes_3D,X+X_Position,Y+Y_Position,Z+Z_Position,'Color',[0, 0.4470, 0.7410]);
%Switch this line to get sphere filled%
% surf(Axes_3D,X+X_Position,Y+Y_Position,Z+Z_Position);
end
Ran using MATLAB R2019b
I have 30 heatmap subplots. How could I present these subplots as an animation or a movie (i.e. one heatmap each 0.5 seconds)?
The subplots are obtained with the following code:
var = {'GeneX','GeneY','GeneZ'};
syms x y z S
alpha_x = 3.9e-2;
beta_x = 6.1;
z_x = 1.3e-5;
n_zx = 2.32;
alpha_y= 4.3e-2;
beta_y = 5.7;
x_y = 7.9e-4;
n_xy = n_zx;
delta_y = 1.05;
x_z = 12e-2;
n_xz = n_zx;
y_z = 11e-3;
n_yz = n_zx;
delta_z = 0.2;
ACDC_X = (alpha_x+beta_x*S)/(1+S+(z/z_x)^n_zx)-x;
ACDC_Y = (alpha_y+beta_y*S)/(1+S+(x/x_y)^n_xy)-delta_y*y;
ACDC_Z = 1/(1+(x/x_z)^n_xz+(y/y_z)^n_yz)-delta_z*z;
ACDCsys_div = [ ACDC_X, ACDC_Y, ACDC_Z ];
J = jacobian(ACDCsys_div,[x;y;z]);
Jsolnew(x,y,z,S) = [J];
%%Construction of the coordinates as a matrix
A = load('matlab.mat','unnamed');% import data from directory
a2 = struct2array(A);% coordinates of the equilibrium point.
numofGraphs = 80;
bx = length(a2(1,1:numofGraphs));
%% Construction of the heatmaps
figure;
hmapax = ceil(sqrt(bx));
for kk = 1:bx %bnx %All bin windows = iteration
JacACDCnew(:,:,kk) = Jsolnew(a2(1,kk),a2(2,kk),a2(3,kk),a2(4,kk));
ACDC_HmapJnew = double(JacACDCnew(:,:,kk));
subplot(hmapax,hmapax,kk);%
heatmap(var,var,ACDC_HmapJnew,'ColorScaling','log');
S = a2(4,kk);
title(['Jac','s=',num2str(S)]);
end
Consider the following example:
function q56130816
% Load some data:
frames = imread('https://i.stack.imgur.com/03kN8.gif');
frames(frames > 1) = 2;
% Create subplots:
figure('WindowState','maximized'); subplot(2,4,1);
for ind1 = 1:8
subplot(2,4,ind1);
imagesc(frames(:,:,1,ind1)); axis image; axis off;
end
colormap([255 255 255; 188 188 188; 244 128 36]./255);
% Capture subplots as frames:
for ind1 = 8:-1:1
frameHolder(ind1) = getframe( subplot(2, 4 ,ind1) );
end
% Play as movie:
hF = figure(); movie(hF, frameHolder, 20, 2);
Which will turn:
Into:
As you can see, in the example above I used getframe, but frames can also be captured using print, as mentioned in the getframe docs. Frames can also be exported to a video file, as explained here.
Animation credit: frames were screen-captured from Johan Lindell's Codepen example.
I have a question about Matlab mesh generations:
How do I manage the size ofthe mesh in Matlab?
What can I do to workaround this error?
Error message
Error using message
Error filling holes for pdelib:initmesh:LargeMesh. Floating point numbers are not
allowed as holes. They should be converted to strings.
Error in initmesh (line 135)
fprintf(['\n' message('pdelib:initmesh:LargeMesh', ntg).getString() '\n']);
Error in pdegplot>plotTwoDGeometry (line 112)
[p1,~,t1]=initmesh(g,'hmax',0.1,'init','on', 'MesherVersion','R2013a');
Error in pdegplot (line 73)
hh = plotTwoDGeometry(g.geom, plotEdgeNums, plotSubLabels);
Error in test_ellips_10 (line 102)
pdegplot(model,'EdgeLabels','on','SubdomainLabels','on')
This Error is generated by Matlab R2015b when the following code is run:
% Rectangle R1
R1_x1 = 0;
R1_x2 = 3810;
R1_y1 = 0;
R1_y2 = 6800;
% Rectangle R2
R2_x1 = (3810/4);
R2_x2 = (3*3810/4);
R2_y1 = (6800+3810/4);
R2_y2 = 6800;
% Rectangle R5
R5_x1 = (3810/4);
R5_x2 = (3*3810/4);
R5_y1 = 0;
R5_y2 = -(3810/4);
% Rectangle R3
R3_x1 = (3810/2-75);
R3_x2 = (3810/2+75);
R3_y1 = (6800+3810/4+100);
R3_y2 = (6800+3810/4);
% Rectangle R4
R4_x1 = (3810/2-75);
R4_x2 = (3810/2+75);
R4_y1 = -3810/4;
R4_y2 = -(3810/4+100);
% Ellipse E1
% pdeellip(xc,yc,a,b,phi,label)
E1_xc = 3810/4;
E1_yc = 6800;
E1_a = 3810/4;
E1_b = 3810/4;
E1_phi = 0;
% Ellipse E2
% pdeellip(xc,yc,a,b,phi,label)
E2_xc = 3*3810/4;
E2_yc = 6800;
E2_a = 3810/4;
E2_b = 3810/4;
E2_phi = 0;
% Ellipse E3
% pdeellip(xc,yc,a,b,phi,label)
E3_xc = 3810/4;
E3_yc = 0;
E3_a = 3810/4;
E3_b = 3810/4;
E3_phi = 0;
% Ellipse E4
% pdeellip(xc,yc,a,b,phi,label)
E4_xc = 3*3810/4;
E4_yc = 0;
E4_a = 3810/4;
E4_b = 3810/4;
E4_phi = 0;
model = createpde(1);
% Rectangle is code 3, 4 sides,
% followed by x-coordinates and then y-coordinates
R1 = [3, 4, R1_x1,R1_x2,R1_x2, R1_x1, R1_y1, R1_y1, R1_y2, R1_y2]';
R1 = [3, 4, R1_x1,R1_x2,R1_x2, R1_x1, R1_y1, R1_y1, R1_y2, R1_y2]';
R2 = [3, 4, R2_x1,R2_x2,R2_x2, R2_x1, R2_y1, R2_y1, R2_y2, R2_y2]';
R3 = [3, 4, R3_x1,R3_x2,R3_x2, R3_x1, R3_y1, R3_y1, R3_y2, R3_y2]';
R4 = [3, 4, R4_x1,R4_x2,R4_x2, R4_x1, R4_y1, R4_y1, R4_y2, R4_y2]';
R5 = [3, 4, R5_x1,R5_x2,R5_x2, R5_x1, R5_y1, R5_y1, R5_y2, R5_y2]';
% Ellipse is code 1, center (E1_x,E1_y), First semiaxis length (strictly positive),Second semiaxis length (strictly positive),Angle in radians from x axis to first semiaxis
E1 = [4,E1_xc,E1_yc,E1_a,E1_b,E1_phi]';
E2 = [4,E2_xc,E2_yc,E2_a,E2_b,E2_phi]';
E3 = [4,E3_xc,E3_yc,E3_a,E3_b,E3_phi]';
E4 = [4,E4_xc,E4_yc,E4_a,E4_b,E4_phi]';
% Pad E1 with zeros to enable concatenation with R1
E1 = [E1;zeros(length(R1) - length(E1),1)];
E2 = [E2;zeros(length(R1) - length(E2),1)];
E3 = [E3;zeros(length(R1) - length(E3),1)];
E4 = [E4;zeros(length(R1) - length(E4),1)];
% Combine the shapes into one matrix
geom = [R1,R2,R3,R4,R5,E1,E2,E3,E4];
% Names for the geometric objects
ns = (char('R1','R2','R3','R4','R5','E1','E2','E3','E4'));
ns = ns';
% Set formula
sf = 'R1+R2+R3+R4+R5+E1+E2+E3+E4';
% Create geometry
DL=decsg(geom,sf,ns);
% Check model
% If all elements of 0 geometry is OK
gstat=csgchk(geom);
% Include the geometry in the model
geometryFromEdges(model,DL);
% View geometry
pdegplot(model,'EdgeLabels','on','SubdomainLabels','on')
xlim('auto')
ylim('auto')
axis equal
generateMesh(model,'Hgrad',1.3,'Hmax',10,'Box','on','Init','on','jiggle','on','MesherVersion','R2013a');
pdeplot(model)
Mathwork's support answer that it's a bug of matlab. To fix you need to patch pdeplot:
>>edit pdegplot
edit the line 112
[p1,~,t1]=initmesh(g,'hmax',0.1,'init','on', 'MesherVersion','R2013a');
change it to
[p1,~,t1]=initmesh(g,'init','on', 'MesherVersion','R2013a');
function [den, p] = findUpperBound(data)
newData = data;
ranData = data;
pValue = Inf;
density = 0.99;
decr = 0.01;
x = [];
y = [];
while(pValue>0.05)
for i=1:numel(data)
newData(i).matrix = findNetworkAtDensity(density, 0.01, data(i).matrix);
newData(i).smallWorldness = (sum(clustering_coef_wu(newData(i).matrix))/90)/avgPathLen(newData(i).matrix);
x(i,1) = newData(i).matrix;
ranData(i).matrix = randmio_und_connected(newData(i).matrix, 5);
ranData(i).smallWorldness = (sum(clustering_coef_wu(ranData(i).matrix))/90)/avgPathLen(ranData(i).matrix);
y(i,1) = ranData(i).matrix;
end
[h, pValue] = ttest2(x,y);
density = density - decr;
end
den = density;
p = pValue;
end
I need to assign some values into newData and ranData, and there is an error:
"Improper index matrix reference. Error in findUpperBound (line 11)newData(i).matrix = findNetworkAtDensity(density, 0.01, data(i).matrix);"
It is weird that if I use the command window to do this, there will be no error:
>> a = data;
>> a(1).matrix = data(1).matrix;
>>
I've search for this on the Matlab site, but still can't find the answer.
Could anyone tell me how to solve this problem? Thanks a lot!
I have to draw a hipsometric map on a 3D plot. I have two vectors 1x401 (named xLabels and yLabels) which are the geo coordinates, and401x401(namedA`) matrix with the altitude data. To plot the data I use:
surf(xLabels, yLabels,A,'EdgeColor','None','Marker','.');
which leads to something like that:
But i would like to have something like that:
On the second image, only the surface is plotted, while my image looks like pillars.
I tried even make my vectors to 401x401 using meshgrid but it did not have any effect.
Do you have any idea what I should change?
#EDIT
I checked for X and Y data. I quess is too small interval (0.0083), but when i try plot good second of upper plots with same interval it draws correctly.
#EDIT2:
sizeX = 4800;
sizeY = 6000;
pixdegree = 0.0083; % 1 pixel is 0.0083 degree on map
intSize = 2;
lon = 37 + (35/60);
lat = 55+ (45/60);
fDEM = 'E020N90';
fHDR = 'E020N90.HDR';
[startXY, endXY] = calcFirstPixel(lon, lat); %calc borders for my area
f = fopen('E020N90.DEM');
offset = (startXY(1,2)*sizeX*intSize)+(startXY(1,1)*intSize);
fseek(f, offset,0); %seek from curr file pos
x = 0;
A = [];
BB = [];
jump = (intSize*sizeX)-(401*2);
while x<401
row = fread(f, 802);
fseek(f, jump, 0); %jump 2 next row
A = [A row];
x = x+1;
end
fclose(f);
A = A';
A = A(:,2:2:802);
m1 = min(A(:)); %wartość minimalna dla naszej podziałki
m2 = max(A(:)); %wartość maksymalna dla naszej podziałki
step = m2/8; % będzie 8 kolorów
highScale = m1:step:m2-step; %wartości graniczne dla każdego z nich
%handles.axes1 = A;
colormap(hObject, jet(8));
startXtick = 20 + pixdegree*startXY(1,1);
endXtick = 20 + pixdegree*endXY(1,1);
startYtick = 90 - pixdegree*endXY(1,2);
endYtick = 90 - pixdegree*startXY(1,2);
[XX,YY] = ndgrid(startXtick:pixdegree:endXtick,startYtick:pixdegree:endYtick);
xLabels = startXtick:pixdegree:endXtick;
yLabels = startYtick:pixdegree:endYtick;
surf(xLabels, yLabels,A,'EdgeColor','None','Marker','.');
set(gca,'YDir','normal');
grid on;
view([45 45])
And .DEM files
function [startXY, endXY] = calcFirstPixel(lon,lat)
global fHDR;
format = '%s %s';
f = fopen(fHDR);
cont = textscan(f, format);
LonStart = str2double(cont{1,2}{11,1});
LatStart = str2double(cont{1,2}{12,1});
diffPerPix = str2double(cont{1,2}{13,1});
fclose(f);
x = LonStart;
countX = 0
y = LatStart;
countY= 0;
while x<lon
x=x+diffPerPix
countX = countX +1;
end
while y>lat
y=y-diffPerPix
countY = countY+1;
end
startXY= [countX-200 countY-200];
endXY = [countX+200 countY+200];
end