https://uk.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-11-20T17:02:06Ztag:uk.mathworks.com,2005:Question/4920092019-11-19T22:42:04Z2019-11-20T17:00:13ZUsing strrep for matrixHello, I have some code that creates a scrambled character block of type char for instance
aaho
aoaa
daa
If i create a variable guess = 'hood'
how could i remove the word hood from the block and then display the block again with the removed 'hood'.
I have tried converting the block to a string array using "string()" then using "strrep() " to remove the the sequence and then convert it back to char but it did not work.
Any suggestions are greatly appeciated. Thanks in advance!Ross Veillonhttps://uk.mathworks.com/matlabcentral/profile/authors/16175695-ross-veillontag:uk.mathworks.com,2005:Question/4920692019-11-20T07:56:06Z2019-11-20T16:58:14Zhow to do Laplace transforms(a) Use symbolic math to find the Laplace transform of the signal
x(t) = e−t sin(2t)u(t).
(b) Use symbolic math to work problem
x(t) = e−4t u(t)+e−5t sin(5t)u(t).
(c) Use symbolic math to find the impulse response of the causal system H1(s)
(d) Use symbolic math to find the impulse response of the causal system H2(s)
(e) Use symbolic math to find the impulse response of the causal system H3(s)
(f) Use symbolic math to find the inverse Laplace transform of X(s) richard harvinshttps://uk.mathworks.com/matlabcentral/profile/authors/16903694-richard-harvinstag:uk.mathworks.com,2005:Question/4906212019-11-12T09:57:21Z2019-11-20T16:57:18ZFind histogram bins at which cumulative histogram has 75% of maximum valueHow to find histogram bins at which cumulative histogram has 75% of maximum value of an imageElysi Cochinhttps://uk.mathworks.com/matlabcentral/profile/authors/3625227-elysi-cochintag:uk.mathworks.com,2005:Question/4921282019-11-20T13:28:37Z2019-11-20T16:56:43ZHow can I see if data fit a specified curve?I have expression data, some are correlated, but some follow a pattern of y = 1/x (only the positive values of x and y).
How do I rapidly tell if the data fit y = 1/x (I have a few thousand pairs of data to try, hence not wanting to plot each one individually). Is there an easy way of doing this with curve fitting functions?Rachael Thompsonhttps://uk.mathworks.com/matlabcentral/profile/authors/16680322-rachael-thompsontag:uk.mathworks.com,2005:Question/4921652019-11-20T16:04:38Z2019-11-20T16:52:09ZUsing pix2map : Coordinates not transforming correctlyI'm reading in a geotiff, obtaining the refmatrix, peforming a calculation, and extracting the pixel values and latitude, longitude values, then writing that to a shapefile.
The resulting data appear to be transformed to the bottom left corner of the latitude longitude limits of the refmatrix. How do I get the values to plot exactly onto the source data? The shapefile latitude and longitude values extracted from the cells of the geotiff seem to be scaled.
I've attached the tif. I thought it might have been the projection, but it appears to an issue with the refmatrix or the values extracted from the geotiff are scaled in some way, but i can't see where. I'm plotting in degrees, and the geotiff is in degrees also.
File_Name='Resampled_130_CHM10cm.tif'
[chm, refmat, ~] = geotiffread(File_Name);
info = geotiffinfo(File_Name)
tallest=max(max(chm));
CHMLOW = im2double(chm2<=(tallest-12),'indexed');
CHMLOW(CHMLOW <= 0) = NaN;
chm = im2double(chm,'indexed');
chm2 = im2double(immultiply(chm,CHMLOW),'indexed');
neigh = [11,11];
low_dtm = blockproc(chm2,neigh,@(s)min(s.data(:)))
data=low_dtm;
[AY, AX]= size (data);
lon = double(zeros(size(data)));
lat = double(zeros(size(data)));
x = double(zeros(1, AX));
y = double(zeros(1, AY));
height=AY;
width=AX;
[rows,cols] = meshgrid(1:width,1:height);
latlim = info.SpatialRef.LatitudeLimits;
lonlim = info.SpatialRef.LongitudeLimits;
NewR = makerefmat('RasterSize', size(data), 'Latlim', latlim, 'Lonlim', lonlim)
[x,y] = pix2map(NewR, rows, cols);
val = ltln2val(data, NewR, y,x);
X = reshape(x,numel(x),1);
Y = reshape(y,numel(y),1);
Z = reshape(val,numel(val),1);
matvals=([X Y Z]);
matvals(any(isnan(matvals), 2), :) = [];
One_percent = prctile(matvals(:,3),[1],1);
indx= find(matvals(:,3)<=One_percent);
matvals=matvals(indx,1:3);
indx= find(matvals(:,3)>= 0);
matvals=matvals(indx,1:3);
Lon = matvals(:,1) ; % longitude
Lat = matvals(:,2) ; % latitude
Ele = matvals(:,3) ; % Elevation of lowest terrain
points = geopoint(Lat, Lon, 'Elevation', Ele)
shapewrite(points,Shape_out) % write into shape file
figure
geoshow(data,refmat)
hold on
geoshow(points.Latitude, points.Longitude, 'DisplayType','point')
Paul Scholefieldhttps://uk.mathworks.com/matlabcentral/profile/authors/3253935-paul-scholefieldtag:uk.mathworks.com,2005:Question/4921732019-11-20T16:47:44Z2019-11-20T16:51:54ZAdd text to individual frame using Videowriter.Hi there,
thanks in advance to all contributions to this post.
I am using the video writer function in Matlab to create a video (.avi) from experimental images (.pngs) that have been collected at a range of temperatures.
I am attempting to add text to each frame (e.g 20°C, 40°C, 60°C etc.) whilst the video is being writen to avoid having to prelabel the images. Would anyone know how to do this?
Many thanks,
Tamsin
Tamsin O'Reillyhttps://uk.mathworks.com/matlabcentral/profile/authors/11401592-tamsin-o-reillytag:uk.mathworks.com,2005:Question/4915332019-11-17T10:17:21Z2019-11-20T16:50:36ZExtract a function from a tableHello,
I really need to clear up my toughts, I want to extract a fonction from a table of two dimensions ( l,t) that I recover from and ODE method.
[t,l]=ode23('odef',[t0,tf],l0)
My goal is to integrate "l" Si I need to have a function to use for exemple the simpson method :
f = inline('l','t')
h = 100/N;
Isim=0.0;
for i=1:N
Isim= Isim+h*(1/6*f(t(i))+2/3*f((t(i)+t(i+1))/2)+1/6*f(t(i+1)));
end
Isim
Of corse this program doesn't work because I used a vecto as a function !
Do you have an idea how can I integrate from data ?
Thank you,
Regards,Sarah CHOUCHENEhttps://uk.mathworks.com/matlabcentral/profile/authors/12914710-sarah-chouchenetag:uk.mathworks.com,2005:Question/4918412019-11-19T07:02:02Z2019-11-20T16:48:57ZHow to find the row numbers of similar elementsHi,
I needed a little help with finding the row numbers of similar elements in a matrix. It involves the use of unique,find and sort commnds but I could not clear the errors that I was facing. My code should do the following:
I have a matrix as follows:
1 3 2
2 4 1
4 3 6
5 1 8
2 8 9
1 7 5
6 6 2
7 9 1
1 3 2
I need my code to first check for similar values in column 1, for example in the above matrix let us consider for the number "1", it occurs three times in column1. So I want my code to check for all the rows in column 1 with a value 1 and then check for the same rows if the corresponding values in column 2 are also same, meaning in the 1st column above the value 1 occurs on rows 1, 6 and 9, then for the same rows the code should check what are the values in column 2, from the matrix it can be noticed that the corresponding values in column 2 for 1 is 3, 7 and 3. After this I need my code to check for the row numbers of similar elemnts that is 3. From the matrix above it is the row numbers 1 and 9. Then I need the code to check for the values in column 3 for rows 1 and 9, if the numbers in column 3 are same then set a variable to 1 otherwise 0. I need the code in a looping structure since I have to check for 50 values.
Any help or suggestions on how to do it is appreciated.
Thanks.Rashmi Mohan Kumarhttps://uk.mathworks.com/matlabcentral/profile/authors/12260533-rashmi-mohan-kumartag:uk.mathworks.com,2005:Question/3996282018-05-08T05:21:49Z2019-11-20T16:48:06Zcharacter/letter data set for matlabMy final project is number plate recognition.i need a data set of A-Z characters and 0-9 letters. i donot find it on any website give me a data set or send me a link. i have to make a neural network in which i put that data set to train and test my data.Shazma Khanhttps://uk.mathworks.com/matlabcentral/profile/authors/12744404-shazma-khantag:uk.mathworks.com,2005:Question/4921722019-11-20T16:47:13Z2019-11-20T16:47:13ZHow can I access a Matlab web app from another computer?Hello,
I have developed a Matlab web app through the app designer tool and have published it through the Matlab web server application. Although I can access the file through the link generated http://hostname:9988/webapps/home/session.html?app=app1 on my PC (same PC as the server), I cannot access it from a different computer (not even in the same network). Do you know how I can generate a link that I can share with people outside my network? I am trying to avoid using Matlab Production Server if possible.
Best regards
SteffenSteffen Ochsenkühnhttps://uk.mathworks.com/matlabcentral/profile/authors/15848789-steffen-ochsenkuhntag:uk.mathworks.com,2005:Question/4921712019-11-20T16:41:29Z2019-11-20T16:46:25ZBuild a Model without source codeHello,
I followed this tutorial in order to send only my simulink model with a s-function as obj to protect intellectual property:
https://uk.mathworks.com/matlabcentral/answers/196427-how-do-i-build-my-model-that-contains-an-rtw-generated-s-function-block-if-i-do-not-have-the-source
but I just can't seem to get it to work because when the receiver build the model, the build fails because it asks for the source code (.c file) again.
what do I possibly miss?Muhammad Halindra Prakosohttps://uk.mathworks.com/matlabcentral/profile/authors/13017581-muhammad-halindra-prakosotag:uk.mathworks.com,2005:Question/4531072019-03-28T16:38:10Z2019-11-20T16:45:24Zhow can i solve this ,can anyone provide me with code? whats wrong with my code ?Write a function called valid_date that takes three positive integer scalar inputs year, month, day. If these three represent a valid date, return a logical true, otherwise false. The name of the output argument is valid. If any of the inputs is not a positive integer scalar, return false as well. Note that every year that is exactly divisible by 4 is a leap year, except for years that are exactly divisible by 100. However, years that are exactly divisible by 400 are also leap years. For example, the year 1900 was not leap year, but the year 2000 was. Note that your solution must not contain any of the date related built-in MATLAB functions.
function [valid]=valid_date(year, month, day)
if isscalar(year) && year>0 && year~=0 && isscalar(month) && month>0 && month~=0 && isscalar(day) && day>0 && ar
if mod(year,4) == 0 && mod(year, 100)~= 0 || mod(year,400)==0 && month==2 && days<=29
%for february
valid=true;
else
valid=false;
end
%for rest of the months
if month==4 || month==6 || month==9 || month==11 && day<=30
valid=true;
elseif month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month== 12 && day<=31
valid=true;
else
valid=false;
end
%not a leap year
if month==2 && day>28
valid=false;
end
%rest of the months
if month==4 || month==6 || month==9 || month==11 && day<=30
valid=true;
elseif month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month== 12 && day<=31
valid=true;
else
valid=false;
end
else
valid=false;
end asad jaffarhttps://uk.mathworks.com/matlabcentral/profile/authors/14997254-asad-jaffartag:uk.mathworks.com,2005:Question/4907972019-11-13T07:02:04Z2019-11-20T16:44:55Zcomparing 3x3 block with center pixeli have a matrix as shown below
i wanted to take a 3x3 pixel and take 3 pixels at a time along with the center pixel,
and compare the selected 3 pixel value with the center pixel,
and if 2 or morepixel has value greater than the center pixel and i wanted to assign 1 to it else 0
So in this case i will get 1-0-0-0 and then convert the binary 1000 to its corresponding decimal value
Then the next 3x3 pixel
Elysi Cochinhttps://uk.mathworks.com/matlabcentral/profile/authors/3625227-elysi-cochintag:uk.mathworks.com,2005:Question/4921382019-11-20T14:05:56Z2019-11-20T17:02:06ZCreating an array from .CSV file data
Hi, I am trying to put the outcome for every piece of data in to one array. The current file I am calling has 89 data samples. However this can change depending on what file the user selects. Do I use an empty array or how do I achieve this?
Array = {}
data = readmatrix(fullfile(path,file)); % Read data from selected file
dataStart = sscanf(input('Enter what row from the file you want the data to begin: ', 's'), '%d');
dataEnd = sscanf(input('Enter the amount of data samples in the data file: ', 's'), '%d');
for i = dataStart:dataEnd
Data1 = data(i,1);
Data2 = data(i,2);
Data3 = data(i,3);
Data4 = data(i,4);
Data5 = data(i,5);
Data6 = data(i,6);
Data7 = data(i,7);
Data8 = data(i,8);
Data9 = data(i,9);
Data10 = data(i,10);
Data11 = data(i,11);
Data12 = data(i,12);
Data13 = data(i,13);
if val3 <= 3 & val5 <= 0
Outcome = 'True';
elseif Datal3 <= 3 & Data1 > 0 & Data4 <= 0 & Data10 <= 0.9 & Data3 <= 1 & Data5 <= 268
Outcome = 'False';
elseif Data3 <= 3 & Data5 > 0 & Data9 <= 0 & Data10 <= 0.9 & Data3 <= 1 & Data6 > 268
Outcome= 'True';
%% ...There are more elseif conditions but I have removed them for this
end
Array = ({Outcome})
end
disp(Array)McGeehttps://uk.mathworks.com/matlabcentral/profile/authors/16602893-mcgeetag:uk.mathworks.com,2005:Question/4911122019-11-14T16:50:24Z2019-11-20T16:42:12Zfind transfer function of input and output signals and then perform an FFT.Hello,
I have collected two signals as input x(t) and output y(t) to the system. I want to find the transfer function(which is basically Output/Input as per my knowledge). But some of the values in the input signal are zero so I think performing this division would give 'divide by zero' error.
I tried using 'tf', 'tfestimate' and 'iddata' on these signals but I am not getting the right plot of the transfer function.
Ultimately after finding the transfer function, I want to perform fft on it and plot a single-sided amplitude spectrum(TF vs freq plot).
Can someone please help me with this? I am new to the Control systems and signal processing concepts so it will be really useful for me to understand the basics.
Thanks.Disha Srivastavahttps://uk.mathworks.com/matlabcentral/profile/authors/9938406-disha-srivastavatag:uk.mathworks.com,2005:Question/4835632019-10-04T08:08:51Z2019-11-20T16:40:59ZLinker issue GPU Coder generated static lib to g++ project.Hi
I generated a static libxyz.a with the GPU Coder on a Jetson Xavier target. Now I want to link this library into an existing g++ project.
Unfortunately I get unresolved symbols which directs to MathWorks methods like __cudaRegisterLinkedBinary_54_tmpxft_000031a2_00000000_6_MWTargetNetworkImpl_cpp1_ii_beb7
An internet search pointed me to a build example for such use case: https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#examples
There's an intermediate linker step (--device-link) used before generating the static library, in this case libgpu.a:
nvcc --gpu-architecture=sm_50 --device-c a.cu b.cu
nvcc --gpu-architecture=sm_50 --device-link a.o b.o --output-file link.o
nvcc --lib --output-file libgpu.a a.o b.o link.o
g++ host.o --library=gpu --library-path=<path> \
--library=cudadevrt --library=cudart
Unfortunately I cannot find this --device-link step in the GPU Coders build log before the static library is linked from the object files.
Is there an coder option to enable such device-linker step? Or how could such unresolved symbold be resolved otherwise?Markus Walserhttps://uk.mathworks.com/matlabcentral/profile/authors/2629911-markus-walsertag:uk.mathworks.com,2005:Question/4919772019-11-19T19:35:27Z2019-11-20T16:40:21ZSurface between 3D linesHi all,
I am trying to link these 3D lines through a surface that pass through all of them, which basically will show the variation between them and it would be great if that will be colored. I attached a pic that clarify my thoughts, and hopefully I will get help!
I tried to use the griddata command but unfortunately it didn't work.
I also attached my code and excel sheet I am working on.
Thanks,
clc
close all
clear all
dataset =xlsread('test.xlsx','N','G1:L203');
D1=dataset(:,2);
F1=dataset(:,1);
F2=dataset(:,3);
F3=dataset(:,5);
colormap hsv
figure(1)
plot (D1,F1,'MarkerSize',15);
hold on
plot (D1,F2,'-','MarkerSize',15);
plot (D1,F3,'--','MarkerSize',15);
hold off
z1=3*ones(201,1);
z2=6*ones(201,1);
z3=9*ones(201,1);
XX = [D1;D1;D1];
YY = [F1;F2;F3];
ZZ= [z1;z2;z3];
Dlin = linspace(min(D1),max(D1));
Flin = linspace(min(F1),max(F3));
Zlin = linspace(min(z1),max(z3));
[X,Y] = meshgrid(Dlin,Flin);
figure(2)
plot3(D1, z1, F1,'-.')
hold on
plot3(D1, z2, F2)
plot3(D1, z3, F3,'--')
grid on
figure(3)
Z= griddata(XX,YY,ZZ,X,Y);
plot3(X, Y, Z);
grid on
axis tight
view(-50,30)Talal Salemhttps://uk.mathworks.com/matlabcentral/profile/authors/16136702-talal-salemtag:uk.mathworks.com,2005:Question/4921682019-11-20T16:24:06Z2019-11-20T16:39:24ZHelp, How to convert image to binary image ?
How to convert this picture to binary image ? I have no idea to write this picture code ! help me Ulzii Bayarhttps://uk.mathworks.com/matlabcentral/profile/authors/16759085-ulzii-bayartag:uk.mathworks.com,2005:Question/1022192009-06-27T01:11:00Z2019-11-20T16:38:44ZHow do I make a figure full screen programmatically in MATLAB?I would like to make my figure "full screen" without using the mouse to maximize the figure window.
MathWorks Support Teamhttps://uk.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:uk.mathworks.com,2005:Question/4921632019-11-20T15:46:11Z2019-11-20T16:36:55ZFunctions in Matlab, problem I have a vector A = (A1, A2, A3) which is orthogonal to another unit vector, v = (v1,v2,v3), whose first coordinate is 0. I have come up with the following:
v2 = [0 A(2) -A(3)];
v3 = [0 -A(2) A(3)];
v2 = v2/norm(v2)
v3 = v3/norm(v3)
But if I want to write/code it as a function instead where A is the input value, how do I do that?
I understand that functions can be written as function[v2,v3] = Name(A3,A2) but how do I do it on above if the function is not given?
I have tried with below but all I get is errors, and furthurmore I do not get the coordinates of the vector:
function[v2,v3] = function1(w2,w3)
v2 = +/-w3/sqrt((w2)^2)+(w3)^2);
v3 = +/-w2/sqrt((w2)^2)+(w3)^2);
Jenny Andersenhttps://uk.mathworks.com/matlabcentral/profile/authors/16767410-jenny-andersentag:uk.mathworks.com,2005:Question/4921322019-11-20T13:39:29Z2019-11-20T16:32:57ZExtract and code gender string as number using if loopI have data for 200 participants stored in a 1x1 structure with 3 fields (time data, gender and age). I'm trying to include lines of script that will extract the gender of each participant and code their gender as 0 (non-binary), 1 (female), or 2 (male). I'm also assigning an ID and extracting age, code so far is below:
for i = 1:size(files);
id = str2num(files(i).name(7:size(files(i).name,2)-4));
tempfile = load(files(i).name);
age = tempfile.data.age;
end
I don't have experience in using an if-loop on strings and am struggling to find the best command to use. I have tried the below, as this is what I would do if extracting and coding numbers, but obviously this doesn't work for these strings as they are not matched in size. I've also played around with STRCMP and STRNCMP but with no luck.
if tempfile.data.gender == 'non-binary'
gender = 0;
elseif tempfile.data.gender == 'female'
gender = 1;
elseif tempfile.data.gender == 'male'
gender = 2;
A little help would be much appreciated! Jenhttps://uk.mathworks.com/matlabcentral/profile/authors/16425632-jentag:uk.mathworks.com,2005:Question/4921692019-11-20T16:24:36Z2019-11-20T16:28:55ZHow to calculate the difference between two Areas?Hi.
I have two areas.
How can I obtain the difference between these two?
How can I then minimize the difference by translating the second area?
Or even better, how can I display the difference between areas as a funcion of the amont of translation done to the second area?
Gabriele Colasurdohttps://uk.mathworks.com/matlabcentral/profile/authors/16783079-gabriele-colasurdotag:uk.mathworks.com,2005:Question/4921702019-11-20T16:27:10Z2019-11-20T16:27:10ZRemoving points from meshgrid (mask)Hey!
I'm trying to remove points from my mesh grid in order to get a graph similar to this one:
Basically I want to remove all the points below the line given in the code below by h1.
clear all; close all; clc % clear variables, close plots, clear screen
%% Constants
D = 60; % Ekman layer depth (m)
rho_0 = 1025; % density (kg/m^3)
f = 0.545/(10^4); % Coriolis parameter
c = (1+i)*pi/D; % c parameter
ug = 0; % zonal geostrophic wind speed
tau_x = 0; % x-component of wind shear stress
tau_y = 0.07; % y-component of wind shear stress
tau = tau_x + i*tau_y; % complex wind shear stress
u0 = (1-i)*pi*tau/(rho_0*f*D); % surface Ekman velocity in the deep ocean limit
hDmax = 2.5; % maximum h/D value
%% Bathymetry
h1 = @(x) -x/1000; % bathymetry profile function
x_grid = linspace(-200000,0,1000); % linearly spaced grid for the horizontal coordinate (offshore distance, x)
z_grid = linspace(-100,0,1000); % linearly spaced grid for the vertical coordinate (depth, z)
h = h1(x_grid); % vector with bathymetry
tmp = find(h/D>hDmax); % reduce offshore grid
xindex = tmp(end);
h = h(xindex:end);
L = length(h);
N = length(z_grid);
zeta = pi*h/D; % vector with zeta function values
%% Horizontally-varying structure functions
alpha = (cosh(zeta).*cos(zeta)).^2 + (sinh(zeta).*sin(zeta)).^2;
S1 = cosh(zeta).*cos(zeta)./alpha;
S2 = sinh(zeta).*sin(zeta)./alpha;
T1 = cosh(zeta).*sinh(zeta)./alpha;
T2 = cos(zeta).*sin(zeta)./alpha;
%% Velocities, transport and stream function
vg = (2*pi*tau_y/(rho_0*f*D)).*(1-S1)./(T1-T2) - ug.*(T1+T2-2.*pi.*h./D)./(T1-T2); % meridional geostrophic wind speed
ugu = h*0 + ug; % adjusting the size of the vector
ugc = complex(ugu,vg); % complex total geostrophic velocity
Uek = abs(tau_y/(rho_0*f)); % Ekman transport
psi = zeros(N,L);
psi = complex(psi,psi);
for jj=1:L
for ii=1:N
psi(ii,jj) = (1/c).*(u0.*(1-(cosh(c.*(z_grid(ii)+h(jj))))./(cosh(c.*h(jj)))) +...
ugc(jj).*sinh(c.*z_grid(ii))./cosh(c.*h(jj)));
end
end
psi = real(psi); % real part of stream function
%% Plotting
X_grid = repmat(-h/D,[N 1]);
Z_grid = repmat(z_grid/D, [L 1]);
Z_grid = Z_grid'
Z = psi/Uek;
contour(X_grid,Z_grid,Z,'ShowText','on','LevelStep',0.1)
The figure produced at the moment is the following:
What can I do?António Lúciohttps://uk.mathworks.com/matlabcentral/profile/authors/5674532-antonio-luciotag:uk.mathworks.com,2005:Question/4919332019-11-19T15:59:02Z2019-11-20T16:25:47Ztwo body problem using ode45% Assumption that earth is orbiting circulary around sun
v=0.0172; % angular velocity of earth [au/day]
p=365; % orbital time of earth [day]
a=1; % orbital radius of earth [au]
[t,x]=ode45(@earth,[0:0.001:p],[a;0;0;v]);
plot(x(:,1),x(:,3));
function dxdt=earth(t,x)
g=2.959*10^(-4);
m=1;
dxdt=[x(2);-g*m*x(1)/(x(1)^2+x(3)^2)^1.5;x(4);-g*m*x(3)/(x(1)^2+x(3)^2)^1.5];
end
theoretically, the earth must moves closed orbit.
but it doesn`t for my code
long time later the earth is converge into sun
what does matter?
siyeong Janghttps://uk.mathworks.com/matlabcentral/profile/authors/16868968-siyeong-jangtag:uk.mathworks.com,2005:Question/4921672019-11-20T16:23:38Z2019-11-20T16:23:38ZQuestion on using geometryFromMeshHi all,
I came across a problem when using geometryFromMesh. I have a mesh file for a 3D geometry generated from COMSOL, and I would like to use it in pde toolbox in MATLAB. The COMSOL file contains the coordinates for the nodes, which is a Nnodes-by-3 matrix and the element information which is a Nelements-by-4 matrix. I rearranged the node matrix and element matrix, and put them in the form in 3-by-Nodes form and 4-by-Nelements form as indicated in https://www.mathworks.com/help/pde/ug/pde.pdemodel.geometryfrommesh.html#buvjb86-nodes
However, there is still a warning saying that there is node ID missing and it should start from 1. However, if I add a row for node ID the matrix will not be 3-by-Nodes.
Is there anything that I missed that caused this problem?
Than you very much!
Best regards,
ShengyueShengyue Shanhttps://uk.mathworks.com/matlabcentral/profile/authors/11913548-shengyue-shantag:uk.mathworks.com,2005:Question/4921502019-11-20T14:45:56Z2019-11-20T16:22:25ZChanging font size of all axes labelsI often need to make pretty cumbersome plotting definitions in MATLAB, an example of which can be seen below
figure(1)
clf
subplot(221)
hold on
plot(z(1,:),...
'LineWidth',2)
line([0,N], [R(1,1),R(1,1)],...
'color','red','linestyle','--','LineWidth',2)
hold off
grid on
xlabel('$k$',...
'interpreter','latex','fontsize',14)
ylabel('$h_1$',...
'Interpreter','latex','FontSize',14)
legend({'closed loop','setpoint'},...
'location','best','fontsize',14)
For simplicities sake I have only included one of four subplots. In these plots I end up writing
'interpreter','latex'
and
'fontsize',14
quite a lot. I am asking if there is a better way to do this given that the font size and interpreter type is the same for my xlabel, ylabel, and legend which it very often is for me.
I have seen some pages recommending I use something along the lines of
set(gca,'fontsize',14)
But this doesnt work for the labels for me.
TLDR: What is a "good" coding style way of configuring the tedious plot options like font size and interpreter en masse.Morten Nissovhttps://uk.mathworks.com/matlabcentral/profile/authors/8733171-morten-nissovtag:uk.mathworks.com,2005:Question/4921472019-11-20T14:34:13Z2019-11-20T16:22:06ZError using vertcat Dimensions of arrays being concatenated are not consistent. I want to make the results for each iteration to display not just the final answer. where the first column is the iteration number and the second column is the result of each iteration.
RRTSS is a called file with an output of " ans = [ t1 dist Reach ] "
size is another variable that contain output.
but the error came out. can anyone help me ??
Ni=2
T = [];
for iteration=1:Ni
RRTSS1
T = [T; iteration size ans] ;
end
T
output :
Error using vertcat Dimensions of arrays being concatenated are not consistent.ARIFF HAIKALhttps://uk.mathworks.com/matlabcentral/profile/authors/15329806-ariff-haikaltag:uk.mathworks.com,2005:Question/4919912019-11-19T20:59:59Z2019-11-20T16:18:14ZCalculate connected graph components of "merged graphs"I have two graphs, G1 and G2, and I would need to calculate the connected graph components conncomp() of the "merged graph" G1+G2.
Here an example:
% Create G1
s = [1 1 2 3 4 4 6 7 8];
t = [2 5 3 5 6 7 9 9 9];
x = [1 1 1 2 2 2 3 3.5 3];
y = [1 2 3 4 1 3 4 3.5 3];
G1 = graph(s,t);
% Create G2
s2 = [1 2 3 4 1];
t2 = [2 3 4 1 5];
x2 = [1.5 1.5 3.5 3.5 1];
y2 = [1.5 3.5 3.5 1.5 1];
G2 = graph(s2,t2);
% Plot G1 and G2
hold on
plot(G1,'XData',x,'YData',y,'linewidth',2,'MarkerSize',2);
plot(G2,'XData',x2,'YData',y2,'linewidth',2,'MarkerSize',2);
hold off
% Calculate conncomp of G1 and of G2
bin = conncomp(G1)
bin = conncomp(G2)
Here below what I would like to get:
% Calculate conncomp of the merged graph G1+G2
bin = conncomp(G1+G2)
Initially, I was thinking to add all the nodes of the smallest graph into the largest one using addnode(), and then calculate conncomp(), but I am not sure about it anymore since I would need to modify iteratively both graphs for several times and calculate the resulting conncomp() after eavery graphs modification....
Any idea about a possible way to do it?Simhttps://uk.mathworks.com/matlabcentral/profile/authors/14233052-simtag:uk.mathworks.com,2005:Question/4920402019-11-20T03:22:16Z2019-11-20T16:18:04ZCalculate derivative using central differencing dx = 0.01;
x = 0:dx:2*pi;
signal = sin(x).*cos(10*x);
dsignaldx_true = cos(x).*cos(10*x) - 10*sin(x).*sin(10*x);
dsignaldx_forward = ForwardO1(signal, x);
dsignaldx_central =
for i =
end
error_forward_max = max(abs(dsignaldx_forward(2:end-1) - dsignaldx_true(2:end-1)));
fprintf('The maximum relative error encountered when using forward differencing with O(dx) error is %f\n', error_forward_max)
error_central_max =
fprintf('The maximum error encountered when using central differencing with O(dx^2) error is %f\n', error_central_max)
error_forward_average = mean(abs(dsignaldx_forward(2:end-1) - dsignaldx_true(2:end-1)));
fprintf('The average error encountered when using forward differencing with O(dx) error is %f\n', error_forward_average)
error_central_average =
fprintf('The average error encountered when using central differencing with O(dx^2) error is %f\n', error_central_average)
Kyle Lazaroffhttps://uk.mathworks.com/matlabcentral/profile/authors/16139723-kyle-lazarofftag:uk.mathworks.com,2005:Question/4921402019-11-20T14:08:57Z2019-11-20T16:17:29ZWrite a program in MATLAB/Octave that generates prime numbers and writes them in the following format.This is my homework for the matlab. Can i get a help for it. Im just new user and I would appreciate any help.
Murat Karahttps://uk.mathworks.com/matlabcentral/profile/authors/16848959-murat-karatag:uk.mathworks.com,2005:Question/4919652019-11-19T18:06:38Z2019-11-20T16:17:26Z Failure in initial objective function evaluation. FMINUNC cannot continue. I tried to evaluate this function but I am getting this error Failure in initial objective function evaluation.
FMINUNC cannot continue.
Please what is the best way to evaluate this function
f = x(2)^2*x(9)^2 + x(2)^2*x(9) + x(2)^3*x(9) - x(3)*x(5)*x(9)^2 + x(6)*x(8)*x(9)^2 + x(6)*x(8)*x(9)^3 + x(2)*x(6)*x(8)*x(9)^2;Kelechi Emerolehttps://uk.mathworks.com/matlabcentral/profile/authors/13086925-kelechi-emeroletag:uk.mathworks.com,2005:Question/4920562019-11-20T06:14:12Z2019-11-20T16:13:07Zerrors in training deep learning network from matlab help system examplesI am try training deep learning network, but the example from matlab help system can not work
clc,clear
[XTrain,YTrain] = japaneseVowelsTrainData;
figure
plot(XTrain{1}')
title("Training Observation 1")
numFeatures = size(XTrain{1},1);
legend("Feature " + string(1:numFeatures),'Location','northeastoutside')
inputSize = 12;
numHiddenUnits = 100;
numClasses = 9;
layers = [ ...
sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer]
maxEpochs = 100;
miniBatchSize = 27;
options = trainingOptions('adam', ...
'ExecutionEnvironment','cpu', ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(XTrain,YTrain,layers,options);
matlab give the following results：
Error using trainNetwork (line 170)
Too many input arguments.
zuiyang shenhttps://uk.mathworks.com/matlabcentral/profile/authors/15376446-zuiyang-shentag:uk.mathworks.com,2005:Question/4921212019-11-20T13:12:01Z2019-11-20T16:11:07ZRank deficient error, how to avoid itQTU = QTU(:), HB=HB(:), P=P(:) ;
HBinv=1./HB;
nqtu = length(QTU) ;
U = ones(nqtu, 1) ;
M = [U P HBinv P.^2 P.*HBinv HBinv.^2]
K = M\QTU
QTU_modele = M*K ;
residus = QTU-QTU_modele;
variance_d_origine = var(QTU) ;
variance_expliquee = var(QTU_modele) ;
variance_residuelle = var(residus) ;
coefficient_correlation_r2 = variance_expliquee/variance_d_origineDaniel Mbadjounhttps://uk.mathworks.com/matlabcentral/profile/authors/8290296-daniel-mbadjountag:uk.mathworks.com,2005:Question/4921312019-11-20T13:35:54Z2019-11-20T16:09:47Zoverlapping different size matrices to make bigger matrixHello, I am new to Matlab and I am developing a code to overlap matrices to make a bigger matrix.
My matrices are of different sizes, I have two matrices of 12x12 in a Struct and one matrix of 12x12 out of Struct. The matrix outside of Struct cannot be added inside the struct.
All three should overlap and make a matrix of 24x24.
S(1).model_data = sparse( rand( 12, 12 )) ;
S(2).model_data = sparse( rand( 12, 12)) ;
and
C = sparse( rand(12, 12));
The overlapping should be done as the last 6 columns of the first matrix and the first 6 columns of the second matrix should overlap, like this last 6 columns of the second matrix and the first 6 colmns of the third matrix should overlap.
I have written some code, but I cannot develop logic for it
s = size(S(1).model_data,1); % size of struct
n = size(S,2) ; % number of matrices in the struct
b = (s+(s-1)+(n-2)*(s-1)+(n-1))-6*(n-1); % size of resulting matrix
T = sparse(b,b) % resulting matrix
But I dont know how to add them diagnoally...
hamzah khanhttps://uk.mathworks.com/matlabcentral/profile/authors/7944651-hamzah-khantag:uk.mathworks.com,2005:Question/1018852013-10-11T09:03:00Z2019-11-20T16:09:43ZHow do I install additional toolboxes into an existing installation of MATLAB?New toolboxes have just been added to my license. How do I install additional toolboxes into an existing installation of MATLAB?
MathWorks Support Teamhttps://uk.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:uk.mathworks.com,2005:Question/4157612018-08-22T07:42:25Z2019-11-20T16:09:20ZHow to get the formula behind a model produced by the regression learner app?Dear all,
I'm using the regression learner app in MATLAB R2017b and was wondering if it is possible to get the formula behind the prediction model? In this case, it's a "Stepwise linear regression".
Thank you!
KryssKrysshttps://uk.mathworks.com/matlabcentral/profile/authors/13340005-krysstag:uk.mathworks.com,2005:Question/4921172019-11-20T12:36:42Z2019-11-20T16:05:50ZReturning to start of statement if error [file,path] = uigetfile('*.CSV'); % Prompting the user to select a .CSV file from their directory
if isequal(file,0)
errordlg('User has selected Cancel', 'File Selection Error');
else
disp(['User selected ', fullfile(path,file)]);
end
Hi For the above code, I would like to return to the start of the code again if the user selects cancel. At the minute an error msg appears but the code ends.
Any ideas?
ThanksMcGeehttps://uk.mathworks.com/matlabcentral/profile/authors/16602893-mcgeetag:uk.mathworks.com,2005:Question/4921662019-11-20T16:05:01Z2019-11-20T16:05:01ZParameterübergabe Gui Funktionen variable Ich habe über gui mehrere Slider erstellt, mir dahinter in eine edit Feld die Zahl ausgeben lassen. Nun möchte ich die Zahlen in einer anderen Funktion "auswerten" bzw weiter behandeln. Komme jedoch nicht weiter, da hier ständig Fehlermeldungen kommen, wenn ich beispielsweise var1 (Wert des sliders) in einer anderen Funktion benutzen möchte. Albin Troghttps://uk.mathworks.com/matlabcentral/profile/authors/16908119-albin-trogtag:uk.mathworks.com,2005:Question/4920612019-11-20T07:14:14Z2019-11-20T16:04:29Zhow to insert a value into the array in a consistent manner.If I want to get [0;1;1;1] when A=ones(3,1)=[1;1;1], I can get [0;1;1;1] by typing [0;A].
If I want to get [0 1 1 1] when A=ones(1,3)=[1 1 1], I can get [0 1 1 1] by typing [0 A].
How can I write them in the consistent way? Must I always use semicolon or space(or comma) dependign on whether A is a row vector or a column vector? Yuki Koyamahttps://uk.mathworks.com/matlabcentral/profile/authors/12950408-yuki-koyamatag:uk.mathworks.com,2005:Question/4921642019-11-20T16:00:01Z2019-11-20T16:03:59ZReading greek letters!I need to read text from an EXCEL file that will include greek letters in some cells. While I can transform the letters (e.g., spelling out "alpha" in place of the actual letter), I need to preserve the content. Currently, when I read the file using readcell, I get the greek letters in the text, but as soon as I try to do anything with them they get substituted with question marks. This is problematic, as I need to make decisions based on the text, and can't do that if every theta, eta, and nu is just going to become identical ?'s.
So, any ideas?Stephen Hallhttps://uk.mathworks.com/matlabcentral/profile/authors/15150782-stephen-halltag:uk.mathworks.com,2005:Question/4921562019-11-20T15:15:56Z2019-11-20T16:01:05ZRandom 2D Spherical Particle DistributionI would like to generate a random 2D spherical particle distribution in a 245mm wide and 100mm high rectangle
Particles must vary in size from 1.5mm to 20mm and not intersect one another.
The particles must occupy 50% of the total volume.
Once generated, id like to export the geometry as a .mph file.
Any guidance on how to achieve this would be greatly appreciated.
Referance image atached.Sean Bondhttps://uk.mathworks.com/matlabcentral/profile/authors/16906878-sean-bondtag:uk.mathworks.com,2005:Question/4857062019-10-16T15:55:30Z2019-11-20T15:55:31ZAccessing S3 compatible file store via URL path - IRI scheme unsupported errorI'm trying to access a self-hosted Amazon S3-compatible datastore (MinIO). I'm trying to access it through a URL path:
https://server_name:9000/bucket_name/file.mf4
Here's a representative sample of the code I'm using:
AWS_ACCESS_KEY = 'xxxxxxx';
AWS_SECRET_KEY = 'yyyyyyy';
setenv('AWS_ACCESS_KEY_ID', AWS_ACCESS_KEY);
setenv('AWS_SECRET_ACCESS_KEY', AWS_SECRET_KEY);
ds = fileDatastore('https://server_url:9000/bucket_name/file.mf4', ...
'ReadFcn', @AWSRead, 'FileExtensions', {'.mf4'});
function data = AWSRead(fileName)
fid = fopen(fileName);
data= fread(fid,inf);
fclose(fid);
end
Matlab says that:
IRI scheme for path: 'path' is unsupported.
It seems that Matlab distinguishes between different remote fileDatastore locations using hard-coded URIs, and does not allow accessing the same resources through a different DNS path.
Is this correct?
In Python I can just do:
s3_resource = boto3.resource('s3',
endpoint_url='https://server_url:9000',
aws_access_key_id = AWS_ACCESS_KEY,
aws_secret_access_key = AWS_SECRET_KEY,
)
s3_resource.Bucket(RIG_NAME).download_file('file.mf4', './file.mf4')
Does Matlab offer similar functionality?Marcin Morawskihttps://uk.mathworks.com/matlabcentral/profile/authors/16590735-marcin-morawskitag:uk.mathworks.com,2005:Question/4921072019-11-20T11:57:43Z2019-11-20T15:49:29ZHow to use a code to get the corresponding value of a loop in another fileI have a particular challenge in a project I am trying to round up. I have two files with loops on both files which I need to interact correspondingly that is to say both files contain the same loops. As such what I am looking is a case where the primary (main) file start with a value of 1 goes to the other file picks the value of one as well run the process have the value comes back thru the loop pick the next value of 2 goes all over again to the secondary file pick 2 comes back till the end of the loop.
The second challenges I am having is the identification of files generated by the second file as that is the information needed by the first file
% This is the first file
function D_fat = scr_response(x)
;;;;;;;;
;;;;;;;;
environment.WaveDirection = 0.0;
for environment_wavedirection = 0:45:360
if environment_wavedirection < 360
environment.WaveDirection = environment_wavedirection;
end
;;;;;;;;;;;;;;
;;;;;;;;;;;;;;
for scores = [caseload01(x),caseload02(x),caseload03(x)]
;;;;;
;;;;;
D_fat = xlsread('filename.xlsx',1,'B8')
D_total = sum(D_fat)
end
end
end
% This is the second file
function seastateload1 = case01(x)
;;;;;;;
;;;;;;;
;;;;;;;
for environment_wavedirection = 0:45:360
if environment_wavedirection < 360
environment.WaveDirection = environment_wavedirection;
end
model.CalculateStatics;
model.RunSimulation; %Run the Dynamic simulation
model.SaveSimulation(sprintf('loadcase1Hs%d.sim',environment.WaveDirection));
%I need the name of the file generated as that is what is needed in file 1
seastateload1 = 'generated file name'
end
endjoshua Abamhttps://uk.mathworks.com/matlabcentral/profile/authors/5181076-joshua-abamtag:uk.mathworks.com,2005:Question/4921592019-11-20T15:29:55Z2019-11-20T15:43:31Zmatlab not reading images from folder in correct sequenceHi, i have stored the images in a folder by name ex. 1.jpg 2.jpg etc. When i am running the code the matlab doesn't read the images in that sequence. Please help
directory = 'C:\Users\Documents\MATLAB\photos';
files = dir([directory '/*.jpg']);
for i = 1:length(files)
image{i} = imread([directory '/' files(i).name]);mukesh bishthttps://uk.mathworks.com/matlabcentral/profile/authors/15950929-mukesh-bishttag:uk.mathworks.com,2005:Question/4917322019-11-18T16:36:01Z2019-11-20T15:42:24ZCoding vectors in matlabHi,
I am trying to put in my code that two vectors w⃗ = (w1, w2, w3) and ⃗v = (v1, v2, v3), with the lenght of 1, are orthogonal to each other and have the first coordinate 0. But I seem to to be getting some errors, I have come up with the following:
v1 = [0 u(3) u(2)];
v1 = v1 / norm(v1);
Jenny Andersenhttps://uk.mathworks.com/matlabcentral/profile/authors/16767410-jenny-andersentag:uk.mathworks.com,2005:Question/4915302019-11-17T09:08:00Z2019-11-20T15:40:23Zfunction checkImageAndNetworkChannelSizesI'm using MATLAB R2019b and I'm trying to create a CNN model that takes grayscale images as input. However, I got the error in checkImageAndNetworkChannelSizes function even though both image channel size and network channel size are 1 because ndims(I) of grayscale image is 2 and therefore the first part of the conditional statement is true. Is this a bug? Is there a way to get around this? I try to add singleton dimension to my image but it seems to be ignored/dropped.
function checkImageAndNetworkChannelSizes(I, networkChannelSize)
% If the input image size has a different channel size than that of
% the network input size, we need to error.
[~, ~, Isize] = size(I);
if ndims(I) ~= 3 || Isize ~= networkChannelSize
error(message('vision:rcnn:invalidInputImageChannelSize', Isize, networkChannelSize));
end
Nichahttps://uk.mathworks.com/matlabcentral/profile/authors/5503137-nichatag:uk.mathworks.com,2005:Question/4918682019-11-19T10:33:32Z2019-11-20T15:38:57ZOrthogonal vectors, how to code? Hi,
I am trying to put in my code that two vectors w⃗ = (w1, w2, w3) and ⃗v = (v1, v2, v3), with the lenght of 1, are orthogonal to each other and have the first coordinate 0. I am able to solve this as an equation system on paper but I am also tying to solve it in matlab. I have come up with the following, but I do not know how to say that the vectors are orthogonal to each other. Any ideas?
v1 = [0 u(3) u(2)];
v1 = v1 / norm(v1);
Jenny Andersenhttps://uk.mathworks.com/matlabcentral/profile/authors/16767410-jenny-andersentag:uk.mathworks.com,2005:Question/4899992019-11-08T14:47:10Z2019-11-20T15:33:21ZPlots graph from simulink scope to App Designer for MATLAB R2019aI have an error using evalin command to plot simulink scope in UI axes - app designer MATLAB R2019a. How to solve this?Nur Huda Mohd Aminhttps://uk.mathworks.com/matlabcentral/profile/authors/16781200-nur-huda-mohd-amintag:uk.mathworks.com,2005:Question/4921602019-11-20T15:30:46Z2019-11-20T15:30:46ZHow to synchronise video to matlab plotI have a video of chopping a potato wherein the chopping activites are captured by a pressure sensor. The data is intepretated and plotted with matlab.
How can I synchronise the video to the plot as to know how the pressure values changes as the video plays.Sujan Ponnappahttps://uk.mathworks.com/matlabcentral/profile/authors/12167526-sujan-ponnappatag:uk.mathworks.com,2005:Question/4900042019-11-08T15:12:58Z2019-11-20T15:27:08ZWhy pcbstack layers not aligned?Hi,
When I use pcbstack my top and bottom layers seem to be offset from the dielectric of the board. I tried to make sure they were centered properly and used the MATLAB docs, but I must be missing something. Any help is much appreciated!
Nick
clear all
close all
clc
c = physconst('lightspeed');
f = 2400e6;
lambda = c/f;
% specs
rH = 0.001016; % radiator width
rW = 0.0198628; % radiator length
fW = 0.001016; % feed arm width
sW = fW; % short arm width
sH = 0.0083058; % distance from end of feed to radiator arm
sep = 0.0027686; % separation between feed arm and short arm
fd = 0.0038608; % distance feed arm goes into into ground plane
fo = 0.02379483; % feed offset from left side of ground plane
trSp = 0.00013746; % clearance around feed (trace clearance)
bW = 0.03403599; % board width
bH = 0.010; % board height
bPcbSp = 0.00025897; % ground plane clearance from pcb edge
bAntSp = 0.000508; % antenna clearance from pcb edge
%
% rH = 1; % radiator width
% rW = 10; % radiator length
% fW = 2; % feed arm width
% sW = fW; % short arm width
% sH = 5; % distance from end of feed to radiator arm
% sep = 4; % separation between feed arm and short arm
% fd = 2; % distance feed arm goes into into ground plane
% fo = 12; % feed offset from left side of ground plane
% trSp = 0.5; % clearance around feed (trace clearance)
% bW = 40; % board width
% bH = 50; % board height
% bPcbSp = 1; % ground plane clearance from pcb edge
% bAntSp = 1; % antenna clearance from pcb edge
% rectangle width / length calculations
b1H = bH;
b1W = bW;
b2W = rW + 2*bAntSp;
b2H = sH + rH + bAntSp - bPcbSp;
g1W = bW - 2*bPcbSp;
g1H = bH - 2*bPcbSp;
g2W = fW + 2*trSp;
g2H = fd + trSp;
fH = sH + fd;
% generate metal shape centers: (0,0) is gnd bottom left
g1X = g1W/2;
g1Y = g1H/2;
g2X = fo;
g2Y = g1H - g2H/2;
fX = fo;
fY = g1H - fd + fH/2;
sX = fX + fW/2 + sep + sW/2;
sY = g1H + sH/2;
rX = sX + sW/2 - rW/2;
rY = g1H + sH + rH/2;
% create metal shape
radArm = antenna.Rectangle('Center',[rX,rY],'Width',rH,'Length',rW);
shortArm = antenna.Rectangle('Center',[sX,sY],'Width',sH,'Length',sW);
feedArm = antenna.Rectangle('Center',[fX,fY],'Width',fH,'Length',fW);
gndBtm = antenna.Rectangle('Center',[g1X,g1Y],'Width',g1H,'Length',g1W);
gndNeg = antenna.Rectangle('Center',[g2X,g2Y],'Width',g2H,'Length',g2W);
shapeTop = radArm + shortArm + feedArm + (gndBtm - gndNeg);
gndBtm = translate(gndBtm,[-g1W/2,-(rY+rH/2)/2,0]);
shapeTop = translate(shapeTop,[-g1W/2,-(rY+rH/2)/2,0]);
% create board shape
b1X = b1W/2 - bPcbSp;
b1Y = b1H/2 - bPcbSp;
b2X = rX;
b2Y = b1Y + b1H/2 + b2H/2;
b1 = antenna.Rectangle('Center',[b1X,b1Y],'Width',b1H,'Length',b1W);
b2 = antenna.Rectangle('Center',[b2X,b2Y],'Width',b2H,'Length',b2W);
boardShape = b1 + b2;
boardShape = translate(boardShape,[bPcbSp,bPcbSp,0]);
boardShape = translate(boardShape,[-bW/2,-(b1H+b2H)/2,0]);
figure
show(shapeTop)
figure
show(gndBtm)
figure
show(boardShape)
% boardShape = antenna.Rectangle('Length',0.6,'Width',0.3);
p = pcbStack;
p.BoardShape = boardShape;
p.BoardThickness = 1.61e-3;
d1 = dielectric('FR4');
p.Layers = {shapeTop,d1,gndBtm};
p.FeedDiameter = .02*lambda/2;
p.FeedLocations = [fX fY-fH/2.1 1];
figure
show(p)Nickhttps://uk.mathworks.com/matlabcentral/profile/authors/14098639-nick