https://la.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-11-18T12:07:36Ztag:la.mathworks.com,2005:Question/4916872019-11-18T12:07:36Z2019-11-18T12:07:36ZHPR Operator not workingI want to use the HPR Operator from Sagi Katz et. al(from this paper) but this error pops up:
Error using builtin
The first input argument must be a double array.
Error in qhullmx
Error in convhulln (line 64)
[k,vv] = qhullmx(x', opt);
Error in HPR (line 29)
visiblePtInds=unique(convhulln([P;zeros(1,dim)]));%convex hull
code:
function visiblePtInds=HPR(p,C,param)
% HPR - Using HPR ("Hidden Point Removal) method, approximates a visible subset of points
% as viewed from a given viewpoint.
% Usage:
% visiblePtInds=HPR(p,C,param)
%
% Input:
% p - NxD D dimensional point cloud.
% C - 1xD D dimensional viewpoint.
% param - parameter for the algorithm. Indirectly sets the radius.
%
% Output:
% visiblePtInds - indices of p that are visible from C.
%
% This code was written by Sagi Katz
% sagikatz@tx.technion.ac.il
% Technion, 2006.
% For more information, see "Direct Visibility of Point Sets", Katz S., Tal
% A. and Basri R., SIGGRAPH 2007, ACM Transactions on Graphics, Volume 26, Issue 3, August 2007.
%
% This method is patent pending.
dim=size(p,2);
numPts=size(p,1);
p=p-repmat(C,[numPts 1]);%Move C to the origin
normp=sqrt(dot(p,p,2));%Calculate ||p||
R=repmat(max(normp)*(10^param),[numPts 1]);%Sphere radius
P=p+2*repmat(R-normp,[1 dim]).*p./repmat(normp,[1 dim]);%Spherical flipping
visiblePtInds=unique(convhulln([P;zeros(1,dim)]));%convex hull
visiblePtInds(visiblePtInds==numPts+1)=[];Lucas Bruderhttps://la.mathworks.com/matlabcentral/profile/authors/15595670-lucas-brudertag:la.mathworks.com,2005:Question/1576332014-10-07T07:39:01Z2019-11-18T12:07:31ZHow getting coordinates of geagraphical locations?Hi,
I have the following struct array.
data=struct('Position',[],'Value',[])
data(1).Position='London';
data(1).Value=20;
data(2).Position='Rome';
data(2).Value=100;
What I need is a bubble plot of values field with a map in the background and the bubble must be located where is the geographical location. I know this function http://www.mathworks.com/matlabcentral/fileexchange/27627-plot-google-map but I don't know how to get the coordinates of the locations. Does anyone have an idea?
Thanks
Cheers
Pietropietrohttps://la.mathworks.com/matlabcentral/profile/authors/1184971-pietrotag:la.mathworks.com,2005:Question/4916862019-11-18T12:02:28Z2019-11-18T12:02:28ZControl of inverted pendulumHello everyone,
I'm playing with the Inverted Pendulum example : openExample('simulink_general/penddemoExample') in Command Window. I'm trying to understand which control theory stays behind the state space estimator and the choice of LQR parameters.
I don't find anything similar in literature, can anyone help me, please? Andrea Gorferhttps://la.mathworks.com/matlabcentral/profile/authors/5102022-andrea-gorfertag:la.mathworks.com,2005:Question/4916832019-11-18T11:53:49Z2019-11-18T12:00:54ZHave data in subfolders availableI have a folder with a MATLAB script. In that folder, I have subfolders with information that can be processed with the MATLAB script. If I want to read a specific file, the only idea I have now is to specify the complete path for each file, with it is tedious.
What I would like is to have all those files available, in the same way that you have available all the data when you are working in the current folder. Is there any way to have available all the data in the subfolders (CSV files, TXT files, etc.)?Neko Benítezhttps://la.mathworks.com/matlabcentral/profile/authors/16473505-neko-beniteztag:la.mathworks.com,2005:Question/4878402019-10-28T13:49:30Z2019-11-18T11:58:24ZR2019a blank property inspector macOS CatalinaHi,
i'm having a boring problem on my Macbook Pro (2016), with macOS Catalina and Matlab 2019a.
I have a figure that i have to modify some style stuffs, and I would like to use the property inspector and get then automatic code for other figures. However, as attached in the screenshot, the property inspector remains blank. Did anyone get this problem and solve it?
Thanks..
Antonio Arenahttps://la.mathworks.com/matlabcentral/profile/authors/7994118-antonio-arenatag:la.mathworks.com,2005:Question/4910522019-11-14T09:47:34Z2019-11-18T11:57:15ZTraining a Variational Autoencoder (VAE) on sine wavesHi,
I am trying to run a variational autoencoder according to the script in https://se.mathworks.com/help/deeplearning/examples/train-a-variational-autoencoder-vae-to-generate-images.html
Basically, I am testing the autoencoder on sine waves. I have a training set and a testing set each having 100 sine waves of length 1100 samples (they are all similar). However, when I try to run the code, I get the following error:
Error using nnet.internal.cnn.dlnetwork/forward (line 194)
Layer 'fc_encoder': Invalid input data. The number of weights (17600) for each output feature must match the number of elements (204800) in each observation
of the first argument.
Error in dlnetwork/forward (line 165)
[varargout{1:nargout}] = forward(net.PrivateNetwork, x, layerIndices, layerOutputIndices);
Error in sampling (line 2)
compressed = forward(encoderNet, x);
Error in modelGradients (line 2)
[z, zMean, zLogvar] = sampling(encoderNet, x);
Error in deep.internal.dlfeval (line 18)
[varargout{1:nout}] = fun(x{:});
Error in dlfeval (line 40)
[varargout{1:nout}] = deep.internal.dlfeval(fun,varargin{:});
Error in ConvAE (line 57)
[infGrad, genGrad] = dlfeval(...
When I run the same code with XBatch = XTrain instead, I get the same error but with number of elements 440000 instead of 204800.
When I run the same code with XBatch = XTrain(idx,:) instead, I get the error: Index in position 1 exceeds array bounds (must not exceed 100).
Can anyone help? I have used the exact same Helper Functions as in the link.
Thanks!
latentDim = 50;
encoderLG = layerGraph([
imageInputLayer([1 1100],'Name','input_encoder','Normalization','none')
convolution2dLayer([1 100], 32, 'Padding','same', 'Stride', 2, 'Name', 'conv1')
reluLayer('Name','relu1')
convolution2dLayer([1 100], 64, 'Padding','same', 'Stride', 2, 'Name', 'conv2')
reluLayer('Name','relu2')
fullyConnectedLayer(2 * latentDim, 'Name', 'fc_encoder')
]);
decoderLG = layerGraph([
imageInputLayer([1 1 latentDim],'Name','i','Normalization','none')
transposedConv2dLayer([1 100], 32, 'Cropping', 'same', 'Stride', 2, 'Name', 'transpose1')
reluLayer('Name','relu1')
transposedConv2dLayer([1 100], 64, 'Cropping', 'same', 'Stride', 2, 'Name', 'transpose2')
reluLayer('Name','relu2')
transposedConv2dLayer([1 100], 32, 'Cropping', 'same', 'Stride', 2, 'Name', 'transpose3')
reluLayer('Name','relu3')
transposedConv2dLayer([1 100], 1, 'Cropping', 'same', 'Name', 'transpose4')
]);
encoderNet = dlnetwork(encoderLG);
decoderNet = dlnetwork(decoderLG);
executionEnvironment = "auto";
XTrain = sineTrain;
XTest = sineTest;
numTrainImages = 1100;
numEpochs = 50;
miniBatchSize = 512;
lr = 1e-3;
numIterations = floor(numTrainImages/miniBatchSize);
iteration = 0;
avgGradientsEncoder = [];
avgGradientsSquaredEncoder = [];
avgGradientsDecoder = [];
avgGradientsSquaredDecoder = [];
for epoch = 1:numEpochs
tic;
for i = 1:numIterations
iteration = iteration + 1;
idx = (i-1)*miniBatchSize+1:i*miniBatchSize;
XBatch = XTrain(:,idx);
XBatch = dlarray(single(XBatch), 'SSCB');
if (executionEnvironment == "auto" && canUseGPU) || executionEnvironment == "gpu"
XBatch = gpuArray(XBatch);
end
[infGrad, genGrad] = dlfeval(...
@modelGradients, encoderNet, decoderNet, XBatch);
[decoderNet.Learnables, avgGradientsDecoder, avgGradientsSquaredDecoder] = ...
adamupdate(decoderNet.Learnables, ...
genGrad, avgGradientsDecoder, avgGradientsSquaredDecoder, iteration, lr);
[encoderNet.Learnables, avgGradientsEncoder, avgGradientsSquaredEncoder] = ...
adamupdate(encoderNet.Learnables, ...
infGrad, avgGradientsEncoder, avgGradientsSquaredEncoder, iteration, lr);
end
elapsedTime = toc;
[z, zMean, zLogvar] = sampling(encoderNet, XTest);
xPred = sigmoid(forward(decoderNet, z));
elbo = ELBOloss(XTest, xPred, zMean, zLogvar);
disp("Epoch : "+epoch+" Test ELBO loss = "+gather(extractdata(elbo))+...
". Time taken for epoch = "+ elapsedTime + "s")
endUermhttps://la.mathworks.com/matlabcentral/profile/authors/6860828-uermtag:la.mathworks.com,2005:Question/4916722019-11-18T10:39:55Z2019-11-18T11:54:32ZPreprocessing using readtable()I have a CSV file that I read it as a table with 'readtable'. The original CSV file contains timestamps for a wide range of days. In most of the cases, I do not need that massive amount of timestamps available, because my analyze is centred in a shorter period. Let me put an example to explain better my problem:
The CSV file contains the timestamps in column 1. It starts at timestamp=1573377305, and it starts increasing the timestamps without a determined size, the next timestamp can be at 8 seconds, the third at 10 seconds and so on. What I know are the timestamps of my analysis, the beginning and the end, but I don't know the number of rows that correspond with that interval.
For instance: my timestamps
1573377305
1573377312
1573377326
1573377334
1573377349
1573377355
1573377365
1573377373
1573377386
1573377393
1573377404
1573377416
1573377427
1573377433
1573377445
1573377455
1573377465
1573377475
1573377485
Imagine that my timestamp for analysis is from 1573377326 to 1573377433. I don't want to read all the previous and end information with readtable(). In this case, I could do DataLines = [4 15], but it is an illustrative example. Imagine that you have much more than 20 timestamps, and what you know is the timestamp from beginning to end.
If I upload all the data with 'readtable()', it is inefficient as I am loading information that I am not going to use. How can I do to select the precise interval I am going to use before using readtable()? Or how can I do this process more efficient?
Neko Benítezhttps://la.mathworks.com/matlabcentral/profile/authors/16473505-neko-beniteztag:la.mathworks.com,2005:Question/4916852019-11-18T11:54:31Z2019-11-18T11:54:31ZSolving a delay differential equation usind dde23I am looking for a reproducible code and I am trying my best to find the results but I am stuck after a stage!! Would be helpful if you can help me
I have a function given below which consist of 5 functions provided
I want to reproduce above equations in the below differential equations:
I need to graph the solution of these differential equations:
f1(G)=209/(1+e^(-G/300V3 +6.6)
f2(G)=72(1-e^(-G/144V3))
f3(G)=0.01G/V3
f4(I)=[90/(1+e^(-1.772log(I/V1) + 7.76))] +4
f5(I)=180/(1+e^(0.29I/V1 -7.5))
dG(t)/dt= Gin-f2(G(t))-f3(G(t))f4(I(t))+f5(I(t-T2))
d(I)/dt=f1(G(t))-I(t)/t1
d(I1(t))/dt= Qf1(G(t))-I(t)/t1 +(1-Q)f1(G(t-T1)
clear all;
clc;
V1=3;Gin=216;alpha=0.5;t1=6;V3=10;tau2=50;Eg=180;tau1=5;tau=[10,50];
sol = dde23(@eq24,[10,50],[210;1;80],[0, 50]);
figure(1)
plot(sol(1).x,sol(1).dy(1,:),sol(1).x,sol(1).dy(2,:),
sol(1).x,sol(1).dy(3,:))
function dy=eq24(~,y,Z)
V1=3; V3=10;
t1=6;
G=y(1);
I=y(2);
I1=y(3);
Glag1=Z(:,1); %Tau1%
Ilag2=Z(:,2); %Tau2%
f1=@(G) 209/(1+exp(-G/300*V3 +6.6));
f2=@(G) 72*(1-exp(-G/144*V3));
f3=@(G) 0.01*G/V3;
f4=@(I) 90/(1+exp(-1.772*log(I/V1) + 7.76)) +4;
f5= 180/(1+exp(0.29*I/V1 -7.5));
dy = zeros(3,1);
dy(1) = 216 - f2(G)-f3(G)*f4(I)+f5(Ilag2);
dy(2)=f1-(I/t1);
dy(3) = alpha*f1(G)-I1/t1 +(1-alpha)*f1(Glag1);
endAniruddh Deshmukhhttps://la.mathworks.com/matlabcentral/profile/authors/15832735-aniruddh-deshmukhtag:la.mathworks.com,2005:Question/4916842019-11-18T11:54:30Z2019-11-18T11:54:30ZStreamline plot not completeI have been trying to make this streamline plot, unfortunately I have not been able to make it complete. I have looked on different forum pages but was not able to find a solution.
My code:
clear, clc
Gamma=-4;
a=1;
b=1;
Q=1;
[x,y]=meshgrid(-1:0.05:4,-1:0.05:1);
u= (y./(2*pi.*(x.^2+y.^2)))...
+(((2*Q.*b)/((a^2)*pi.*Gamma))...
.*((2*y.*(x-1))./((x.^2+y.^2-2.*x+1).^2)));
v= -((x)./(2.*pi.*(x.^2+y.^2)))...
-(((2*Q*b)./((a^2)*pi.*Gamma))...
*(((x.^2-y.^2-2.*x+1)./((x.^2+y.^2-2.*x+1).^2))));
hold on , clf
figure(1)
quiver(x,y,u,v)
N = 15;
startx = max(x).*rand(N,1);
starty = max(y).*rand(N,1);
streamline(x,y,u,v,startx,starty)
startx2 = -max(x).*rand(N,1);
starty2 = -max(y).*rand(N,1);
streamline(x,y,u,v,startx2,starty2)
startx3 = rand(N,1);
starty3 = rand(N,1);
streamline(x,y,u,v,startx3,starty3)
hold off
Eddwardhttps://la.mathworks.com/matlabcentral/profile/authors/4550918-eddwardtag:la.mathworks.com,2005:Question/4916812019-11-18T11:41:00Z2019-11-18T11:47:54ZCreate an error functionHi,
I have 2 matrices of images, with all values 0 and 1. I would like to compare the two, where i would like to get the number of true positives (where both pixels -at the same postion- are equal to 1), true negatives (both pixels equal to 0), false positives ( where image A is equal to 1 but image B is equl to 0) and false negatives (where image A is equal to 0 but image B is equal to 1).
If I try to extract where A==1 and B==1 etc. and compare it, I get an error because the matrices dont agree.
If I just compare A to B I only get where the match/not match but it doesnt tell me if its a true positive etc.
thank youudi ibguihttps://la.mathworks.com/matlabcentral/profile/authors/13125259-udi-ibguitag:la.mathworks.com,2005:Question/4916822019-11-18T11:47:33Z2019-11-18T11:47:33Zhow convert txt file into excel file ?Eg :
text file contains
kar_po_data_3_table.kar_po_data_3_basic.q2p_rc_m_ta_h3_cm_vc[0]=0.079387;
kar_po_data_3_table.kar_po_data_3_basic.p2e_rcs_m_ta_h3_cm_vc[1]=0.04785;
....
....
.....
final output : Excel file
kar_po_data_3_table kar_po_data_3_basic.q2p_rc_m_ta_h3_cm_vc[0] 0.03874
kar_po_data_3_basic.p2e_rcs_m_ta_h3_cm_vc[1] 0.04785
.... ...
.... ....
.... ....
.... .....kHhttps://la.mathworks.com/matlabcentral/profile/authors/10661566-khtag:la.mathworks.com,2005:Question/4072282018-06-25T07:37:44Z2019-11-18T11:44:56ZDisplay results in GUI and real timeHello everyone, I got some data from Matlab and plotted some figures to show the relationships between some parameters and the results, for example, if I change some parameters, the results and the figures would also change. However, I want to build a GUI for this model, which could display the results in real time (step by step), and when I change some parameters in GUI, the results curves would also change accordingly and then converge at another value. Could I achieve this in Matlab? I will appreciate your any help.Hao Shihttps://la.mathworks.com/matlabcentral/profile/authors/13061398-hao-shitag:la.mathworks.com,2005:Question/4915332019-11-17T10:17:21Z2019-11-18T11:44:04ZExtract 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://la.mathworks.com/matlabcentral/profile/authors/12914710-sarah-chouchenetag:la.mathworks.com,2005:Question/4909512019-11-13T21:18:33Z2019-11-18T11:39:59Zhow to index a cell array?Hallo,
I have a structure (K) with many fields, containg a field (elevation) which is (161*1 cell) array, each cell is a matrix (n*1) double.
I wanted to find all the elements in each matrix that is more than 0 then calculate the area of these values (above 0)
firstly I made a new cell array of the indexs that I needed
idx = arrayfun(@(K) K.elevation >=0, K, 'UniformOutput', false)';
now I want to use the function trapz to find the area
I tried many things, but I'm getting always errors like 'Unable to use a value of type cell as an index or 'Expected one output from a curly brace or dot indexing expression, but there were 161 results'
Can someone help me with this issue?
many thanks!
YHhttps://la.mathworks.com/matlabcentral/profile/authors/9018683-yhtag:la.mathworks.com,2005:Question/4916792019-11-18T11:28:37Z2019-11-18T11:38:45ZHow is the average and normalization of each column in the table using "for" loop?I have a table with 50x10. In the table, first column is Genes and the second column will be reference column for normalization. Other 8 column will divide reference column. Afterward, this table will be normalized and each column will be averaged after normalization. Therefore there will be one row and 8 columns. How can I do this process in a table. Is it necessary to convert this table to a matrix or dataset, or can we solve it with a simle loop?
I m trying this code for table:
%import data
GSE = readtable("GSE.xlsx", "UseExcel", false);
for i = GSE{3:10:end}
res = GSE{:,i}/GSE{:,2};
...(I dont have an any idea for normalization with this method)
res_m = mean(normalize);
%then the any plot
end
Bu code is not working as I want
% Genes gsm335244 gsm335245 gsm335246
% A1CF 1,194 0,848 0,905
% A2M 0,325 6,301 0,607
% A4GALT 1,048 0,592 1,964experthttps://la.mathworks.com/matlabcentral/profile/authors/15223270-experttag:la.mathworks.com,2005:Question/4916702019-11-18T10:18:42Z2019-11-18T11:35:40ZConditional calculations on a numeric matrixHi All,
I'm relatively new to Matlab and I find myself slightly stuck. I have a numeric matrix of numbers comprising of floating point values. Depending on whether the value in each cell is less than or greater than some threshold value, either one or another calculation is made.
Below is a much simplified expression of my problem but it illustrates the form of what I'm trying to do with millions of cells of values which takes a rather longer time than the illustration below.
I realise that I can make a logic matrix from the input matrix but then I'm stuck on what follows to complete the calculations.
Any advice is gratefully received.
input = magic(10);
thresholdvalue = 50;
for col = 1 : 10
for row = 1 : 10
if input(row,col) > thresholdvalue
result(row,col) = input(row,col)*2;
else
result(row,col) = input(row,col)/2;
end
end
endWah On Hohttps://la.mathworks.com/matlabcentral/profile/authors/6051497-wah-on-hotag:la.mathworks.com,2005:Question/4913502019-11-15T20:11:26Z2019-11-18T11:34:18ZHarmonics of Fourier series How do I Plot the 1st, 3rd and 5th harmonic of the Fourier series,
z(t)= 3/2 + 6/pi sin(t) + 6/3pi sin(3t) + 6/5pi sin(5t) + ...
individually overlapped on one plot.
Ben Hamillhttps://la.mathworks.com/matlabcentral/profile/authors/16465877-ben-hamilltag:la.mathworks.com,2005:Question/4916802019-11-18T11:30:16Z2019-11-18T11:33:31ZSaving geotiff using geotiffwriteHello,
I produced a new variable (mapfinal) in the workspace by subtracting one geotiff from another (they are images of cities).
I want to save this as a geotiff using the function geotiffwrite.
geotiffwrite(mapfinal, info.SpatialRef, ...
'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
How should I write the code?
Thank you!
Sarah Yunhttps://la.mathworks.com/matlabcentral/profile/authors/16837202-sarah-yuntag:la.mathworks.com,2005:Question/4915722019-11-17T17:09:19Z2019-11-18T11:29:43ZUsing existing arrays in workspaceHello,
I am currently writing some code which finds the eigenstates of a Hamiltonian, but each time I run the code I need to solve a nonlinear differential equation. The solutions of this equation are saved into an array in the workspace.
I need to trouble shoot the code constantly, so it is annoying waiting for this nonlinear equation to be solved, and I need a fairly fine mesh to get my code working properly, so I am wondering if there is a way for me to bypass the boundary value problem solver and just take the existing solution out of my work space provided it is already there?
I appreciate any help I can get!
-Marcus
*I should also add I am just commenting out the line which uses bvp4c after I get the solution in the workspace, but would like to know if there is an automatic way to do this.Marcus Rosaleshttps://la.mathworks.com/matlabcentral/profile/authors/7835065-marcus-rosalestag:la.mathworks.com,2005:Question/4916682019-11-18T10:05:20Z2019-11-18T11:27:12ZMean of array columns with conditionI have an array of which I need the mean of each column (X). Additionally, I have a logical array of which rows meet a condition and should be included in the mean (Y).
Naturally, the mean function in MATLAB calculates each column mean, but when I insert the logical vector for the row selection, the mean is calculated for the whole array. How do I fix this for computing the mean of each column in X for the valid indices of Y?
When entering
means_active = mean(X(Y), :);
I get the error 'Reference to a cleared variable mean.', though I don't want to use any variable 'mean' but the built-in function 'mean'.Mariella Dreißighttps://la.mathworks.com/matlabcentral/profile/authors/10265435-mariella-dreissigtag:la.mathworks.com,2005:Question/4916772019-11-18T11:03:25Z2019-11-18T11:25:37Zadding constant offset to sensor hello there
how can i add a constant offset to my sine wave( zero offset ), then be able to plot the sine wave i have added offset to on top of my original sine wave, i have atttched a picture of what i am talking about.
original sine wave
a=0.5 % amplitude
f=5 % frequency
acc = -4*a.*pi^2./f.^2 .* sin(2*pi./f .* t);
t=linspace(0,10,500);
plot(t,acc)
any help would be very much appreciated
thank youMat CRhttps://la.mathworks.com/matlabcentral/profile/authors/14197618-mat-crtag:la.mathworks.com,2005:Question/4913532019-11-15T20:21:14Z2019-11-18T11:25:30Zlot of throughput doesn't shown clc;
close all;
%common parameters
f=6; %Frequency band [GHz]
pt=33; %transmitter power[dBm]
pr=27; %Receiver power[dBm]
n=5; %Noise figure [dBm]
Amu=10; %The median attenuation relative to free space
gt=6; %Transmitter Antenna Gain [dBi]
gr_s=2; %Receiver Antenna Gain [dBi] (stations)
B=20; %Bandwidth [MHz]
L=0.3; %Connector loss [dB]
I=1; %Interference margin loss [dB]
rs_t=-89; %Transmitter Rx Sensitivity [dBm]
rs_s=-91 ; %Receiver Rx Sensitivity [dBm]
d=0:1:10; %The range of the distance between TX and RX
%Data from user
area_type =input ('Enter type of city (1 - urban, 2 - suburban, 3 - rural):','s');
ht=input('Enter the receiver antenna height 30m<hre<1000m : ');
hr=input('Enter the receiver antenna height 1m<hre<10m : '); % Mobile Antenna Height
% Okumura Propagation Model
Lf=32.44+20*log(f)+20*log(d); %Free Space Propagation Loss
Ght=20*log(ht/200); %Transmitter Antenna Height Gain Factor
if(hr<3) %Reciver Antenna Height Gain Factor
Ghr=20*log(hr/3);
else
Ghr=10*log(hr/3);
end
Garea=13;
L50=Lf+Amu-Ght-Ghr-Garea;
Rss=pt+gt+gr_s-L50-L;
SNIR=Rss/(n+I);
Throughput=B.*log2(1+(10.^(SNIR(end)/10)));
for r=1:10
L50=Lf+Amu-Ght-Ghr-Garea;
Rss=[Rss*(pt+gt+gr_s-L50(end)-L)];
SNIR=[SNIR*(Rss(end)/(n+I))];
Throughput=Throughput.*(B.*log2(1+(10.^(SNIR(end)/10))));
end
hold on;
figure (1)
subplot(2,2,1)
plot(d,L50,'LineWidth',1.5)
title('Okumura Model Analysis- Urban');
xlabel(' distance (Km)');
ylabel('Propagation Path loss(dB)');
subplot(2,2,2)
plot(d,Rss,'LineWidth',1.5)
title('Okumura Model Analysis- Urban');
xlabel(' distance (Km)');
ylabel('RSS');
subplot(2,2,3);
plot(d,SNIR,'LineWidth',1.5)
title('Okumura Model Analysis- Urban');
xlabel(' distance (Km)');
ylabel('SNIR');
subplot(2,2,4);
plot(d,Throughput,'LineWidth',1.5)
title('Okumura Model Analysis- Urban');
xlabel(' distance (Km)');
ylabel('Throughput');
hold off;Shahd Altalhihttps://la.mathworks.com/matlabcentral/profile/authors/16739906-shahd-altalhitag:la.mathworks.com,2005:Question/4916742019-11-18T10:59:57Z2019-11-18T11:22:59ZDistance between two point with the same valueHi,
I have a matrix like the one below and i need to get the mean distance between each 3, each 2 etc...
I tried to use several diastance function (like pdist etc) but none of these give an exploitable result (or maybe i misunderstood how its work).
Thank you for your help.
n=randi(3,10)
n =
1 2 3 2 1 1 2 1 3 1
2 1 3 2 1 3 1 1 2 3
3 3 2 3 2 2 2 3 2 3
1 1 2 2 1 1 3 1 1 3
1 3 2 2 3 3 1 3 2 1
1 1 1 3 1 3 1 3 2 1
2 2 2 3 1 2 1 2 3 2
3 2 2 2 1 1 1 2 2 3
2 3 3 2 1 1 2 1 2 1
2 1 3 2 2 2 2 2 3 1Silnaehttps://la.mathworks.com/matlabcentral/profile/authors/14588655-silnaetag:la.mathworks.com,2005:Question/4916782019-11-18T11:22:21Z2019-11-18T11:22:21ZProblem with saving handles using GUIDEHi all,
I'm currently writing a script that takes a workspace from a complex script, takes an array from said workspace and filters through it to find values which lie between two specified values and saves to a new array. This is then going to be input into another script for a calculation to be performed.
The prior complex script makes use of GUIDE, so the workspace features handles.mat.
In the filter script that I'm writing, I'm trying to save the data with the entire pre-existing workspace, plus the new array. The problem that I have is that for some reason, when I'm using the likes of save(filename) etc, it's not saving handles.mat.(everything within this) alongside the pre-existing workspace and the new array created.
How can I overcome this problem?
Thanks in advance!
Nicola Fairbairnhttps://la.mathworks.com/matlabcentral/profile/authors/8907362-nicola-fairbairntag:la.mathworks.com,2005:Question/4916732019-11-18T10:59:51Z2019-11-18T11:22:01ZPolar plot from (excel)matrixHi,
I have a excel file (attached) with values for one angle (0-90 first in 0.5 degree then 5 degree steps) and for another (0-360 in 1 degree steps). I want to make a polar plot, to be exact this one (this is what the data should represent):
How do I do this?
One problem is that the dimensions are not equal, i have 360x73 values, how do I interpolate?MarinoMhttps://la.mathworks.com/matlabcentral/profile/authors/7285541-marinomtag:la.mathworks.com,2005:Question/4835652019-10-04T08:41:39Z2019-11-18T11:15:05ZError using R2019b version of the MATLABJust installed R2019b MATLAB.
SDR with AD9361 is attached to the Host machine.
The host machine's IP is set to 192.168.3.1
The radio is attached to 192.168.3.14.
Now I try to run the following matlab code:
"Transmit and Receive LTE MIMO Using Analog Devices AD9361/AD9364"
I get the following error:
Error using matlabshared.internal.ssh2client
Error connecting to SSH server at 192.168.3.14
Error in matlabshared.socutils.internal.ipcorereg.system
Error in matlabshared.socutils.internal.ipcorereg.IPCoreRegWrite/stepImpl
Error in comm.zynqradioshared.base/writeReg
Error in comm.zynqradioshared.base/initRegisters
Error in comm.zynqradioshared.tx/sdrDevPreInit
Error in comm.libiio.AD9361.base_control/configureChanBuffers
Error in comm.libiio.AD9361.base/configureChanBuffers
Error in matlabshared.libiio.base/setupImpl
Error in comm.libiio.AD9361.base_control/setupImpl
Error in comm.libiio.AD9361.base/setupImpl
Error in comm.libiio.AD9361.tx_control/setupImpl
Error in comm.libiio.AD9361.tx/setupImpl
Error in comm.zynqradioshared.tx/setupImpl
Error in comm.libiio.AD9361.tx/transmitRepeat
Error in finalMIMOad9361 (line 168)
transmitRepeat(sdrTransmitter,eNodeBOutput);
Can someone help me to solve this problem? I want to run two SDR connecting
and sending data on the air.jarulhttps://la.mathworks.com/matlabcentral/profile/authors/7422232-jarultag:la.mathworks.com,2005:Question/4916762019-11-18T11:03:09Z2019-11-18T11:14:20ZI have this code but I want to add each of my values of xn into an array then plot these on a graph. How would i do this?a = input('Enter a value for a');
e = input('Enter a maximum error');
xn = input('Enter a starting value');
y=1;
while abs(y)>=e
xn=(xn+a./xn)./2;
y=xn.^2-a;
end
disp(['The estimated value of the square root of a is: ', num2str(xn)])
ra=sqrt(a);
disp(['The actual value of the square root of a is: ', num2str(ra)])Lewis Harringtonhttps://la.mathworks.com/matlabcentral/profile/authors/16636173-lewis-harringtontag:la.mathworks.com,2005:Question/4022952018-05-24T07:15:11Z2019-11-18T11:06:27ZCreate and fill in a table in Microsoft Word with Actx Server from MATLABHello,
I want to create a table and fill it with variables in Microsoft Word with the Actx Server from MATLAB. I searched a lot but couldn't find a solution.
I also tried some available functions (toTable.m, table2word.m,..) but they didn't work at all.
It would be great if somebody could show me how to create the following table:
The table should have 7 rows and 2 coloums. Another thing i'd like to know is how to merge or divide cells in this table.
I am using Word 2013 and MATLAB R2011b.
Thank you in advance!
ABCDhttps://la.mathworks.com/matlabcentral/profile/authors/9243283-abcdtag:la.mathworks.com,2005:Question/4906072019-11-12T08:32:56Z2019-11-18T11:02:15Zreadcell does not import last columns when first columns are empty (2019a)readcell('test.xls') does not import last n columns, when first n columns are empty.
i.e. instead of
{missing} {missing} {a} {b} {c} {d}
I will get
{missing} {missing} {a} {b}
When I know the number of columns I have I can use i.e.:
readcell('test.xls', 'Range', 'A:F') - in this case I have the last columns, but the leading empty columns are removed:
{a} {b} {c} {d}
Is there a way to get all the columns (including empty one)?
Edit:
readcell('test.xls', 'Range', '') - helps when one do not know the number of columns, but do not include the missing leading rows.
Martin Jandackahttps://la.mathworks.com/matlabcentral/profile/authors/4478610-martin-jandackatag:la.mathworks.com,2005:Question/4916752019-11-18T11:01:48Z2019-11-18T11:01:48ZHow can I work with the deep learning toolbox when dealing with large datasets that are NOT images?Hello,
It's my first time dealing with the Deep Learning Toolbox and with large datasets in Matlab, so honestly, any help or direction you can give me will be extremely helpful. I'm finding it really hard to start since most of the documentation is about how to work with images, and I'm working on a different problem.
I have run simulations in Simulink and have over 2000 files with over 50000 timesteps each (about 100GB of data). Each of these files have about 60 parameters recorded, of which I want to use 39 as inputs and 2 as targets for my training (the remaining parameters would not be used for training). I do not want to train the network for a timeseries, so each timestep is a separate/independent datapoint in my training.
So far I know that:
100GB of data is too much to load for training
There are some "datastore" functions I can use to somehow load/read the data but not use memory in it. Not entirely sure this is correct but the documentation linking datastores to Deep Learning Toolbox only considers images which makes it a bit harder to understand.
And I have divided my task into some steps I think I need to follow:
Build a datastore reading function (custom) that reads my files and extracts the 41 variables I need for training. a) I have no idea what this reading function even looks like or how it should be written. b) I do not know the format I need for these training variables, some are inputs and some targets,... how does the network deal with this, how do you specify which ones?
Find a way to get the data into the training function. Examples, again, are focused on images and it's hard to extrapolate that into different examples. In my case, each file has over 50000 training samples (multiplied by the 41 variables involved); if these were images, each file would be one single image. How does the training function understand this? How do I specify that it must deal with the samples in that way?
I will emphasise I have read the documentation already, on Deep Learning Toolbox, training and the datastore: half of the things I don't understand what they mean or I'm not able to extrapolate to my problem. I would appreciate if anyone that has worked on this for longer could give me a hand by explaining some things to me, pushing me into the right direction,...
Thanks!Ana Guerra Langanhttps://la.mathworks.com/matlabcentral/profile/authors/8804292-ana-guerra-langantag:la.mathworks.com,2005:Question/925652011-02-07T19:41:00Z2019-11-18T10:55:47ZHow do I control axis tick labels, limits, and axes tick locations?I would like to know if I have to set the XTickLabel, YTickLabel, ZTickLabel, XTick, YTick, and ZTick properties.
MathWorks Support Teamhttps://la.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:la.mathworks.com,2005:Question/4916632019-11-18T09:43:52Z2019-11-18T10:54:53ZHow to name row in uitable.As shown in the figure, for example, when the number of data lines I input is equal to 5 (greater than 4), I hope that the number of lines of uitable can be "BS 5".
How do you make the line name change with the amount of data?
han hanhttps://la.mathworks.com/matlabcentral/profile/authors/13769741-han-hantag:la.mathworks.com,2005:Question/4867262019-10-22T09:11:32Z2019-11-18T10:54:30ZApp Designer - Tab between fields order issueI have a simple app with mainly numerical edit fields. The user should be easily able to enter numbers into fields and press tab to move the cursor to the next field. I have several panels and each panel contains several numerical edit fields. However, when the tab key is pressed the curor does not always go to the numerical edit field directly below. It may skip the panel below, then 'bounce around' the fields within one panel and then go to the panel above.
I cannot see a way to change the order the cursor moved between fields when tab key is used. Is there a way to ensure the cursor moves to the correct field when tab key is pressed?Joseph Sherratthttps://la.mathworks.com/matlabcentral/profile/authors/10286243-joseph-sherratttag:la.mathworks.com,2005:Question/4916322019-11-18T05:13:50Z2019-11-18T10:49:03Zhow can I make these image?no11=imread('no1.jpg');
no22=imread('no2.jpg');
bno1 = rgb2gray(no11);
bno2 = rgb2gray(no22);
subplot(2,2,1); imshow(bno1);
subplot(2,2,2); imshow(bno2);
mag1 = abs(fft2(bno1));
mag2 = abs(fft2(bno2));
phas1 = angle(fft2(bno1));
phas2 = angle(fft2(bno2));
C = imfuse(phas1,mag2);
D = imfuse(phas2,mag1);
A = ifft2(C);
B = ifft2(D);
subplot(2,2,3); imshow(A);
subplot(2,2,4); imshow(B);
this is my code and i tried to get the picture of
but the result is
How should I fix it??DOHYUN JANGhttps://la.mathworks.com/matlabcentral/profile/authors/16409707-dohyun-jangtag:la.mathworks.com,2005:Question/4916672019-11-18T10:03:05Z2019-11-18T10:47:15ZHow to convert a variable which has binary data in .mat format to .txt?I have 228796×8 double data in .mat format.I need to convert that into .txt format.How can I do that? Please help me out.
Thank you!N M Channabasavayyahttps://la.mathworks.com/matlabcentral/profile/authors/14634007-n-m-channabasavayyatag:la.mathworks.com,2005:Question/4837922019-10-06T06:23:04Z2019-11-18T10:43:42ZHow to save continuous sound signal into excel ?I want to save the continuous sound signal (24*7) coming from audio jack of PC into the excel (Single excel file for a day). This continous signal is downsampled and final data will be in the range of 10780 * 640 of matrix. PARAG CHOUREYhttps://la.mathworks.com/matlabcentral/profile/authors/11403839-parag-choureytag:la.mathworks.com,2005:Question/4908882019-11-13T15:17:44Z2019-11-18T10:43:32ZFor loop only saving my last runfor i = 1:2
Result(i) = norm(vcu(i,:))
end
p=0
for k = 1:2
ada = vcu(k,:)/Result(k)
end
Where vcu is a vector (a,b,c;a2,b2,c3)
when I run the code I get 2 1x3 vectors as ada but when I want to use ada further in my code it does not work because ada is only saved for k=2Erichttps://la.mathworks.com/matlabcentral/profile/authors/15980494-erictag:la.mathworks.com,2005:Question/4912082019-11-15T04:21:50Z2019-11-18T10:40:34Zhow do you take the mean across columns but for singular row in a 960x31 arrayhelp!!
I have 960 rows in all the cells there are reaction times, then there are 31 columns, I cant remember how to do thisNadiyah Browninghttps://la.mathworks.com/matlabcentral/profile/authors/16068229-nadiyah-browningtag:la.mathworks.com,2005:Question/4782302019-08-30T08:24:25Z2019-11-18T10:38:40ZROS raspberry pi and teensy?I working on a project for prototype of new robotic. I have a raspberry pi and i know already there is a siumlink box for ros on raspberry pi, but my question is : if i have another board ( ardunio or teensy ) connected with raspberry pi with serial port, and i want to publish a message from this board and make raspberry pi subscribe this message, is it possible to do that with ros simulink, or shouldl i publish the teensy message through ros kinetic on raspberry pi and use the ros simulink to subscribe the message ?
I assumed that i install ros kinetic on raspberry pi also i installed rosserial_arduino or rosserial_teensy depending on which board i will use.
Mohamed Khaledhttps://la.mathworks.com/matlabcentral/profile/authors/15745626-mohamed-khaledtag:la.mathworks.com,2005:Question/4914502019-11-16T16:18:08Z2019-11-18T10:34:49ZMean of 72720 rows in one column such that I can take mean of 720 rows separately.Hello!
I have data of 72720 rows in one coloumn. I want to take the mean of each 720 rows and then plot a graph.
Thank youAnas Raohttps://la.mathworks.com/matlabcentral/profile/authors/16318435-anas-raotag:la.mathworks.com,2005:Question/4838802019-10-06T19:11:21Z2019-11-18T10:29:48ZBar Graph attached to Live mapingCODE:
function [red, green, blue] = colorAnalysis(r)
i=1;
img(i)=r.getImage; %Get image from rasberry pie camera on roomba and store in variable 'img'
red = mean(mean(img(:,:,1))); %average red intensity
green = mean(mean(img(:,:,2))); %average green intensity
blue = mean(mean(img(:,:,3))); %average blue intensity
if r.setDriveVelocity(0)
[red(i), green(i), blue(i)] = colorAnalysis(r);
i=i+1;
bar(red(i), green(i), blue(i))
SendData
end
end
Hi, I was wondering if I could place these images or colors onto a live mapping graph. Basically where the picture is taken, the color analysis onto that point of the graph.Alvin Winterhttps://la.mathworks.com/matlabcentral/profile/authors/13974529-alvin-wintertag:la.mathworks.com,2005:Question/4916712019-11-18T10:28:38Z2019-11-18T10:28:38ZHow to remove candidates which are present on blood vessels? Hello,
I am trying to remove pixels which are present on the blood vessels.I have two images ,one is the candidates image and the blood vessels image.I have studied that candidates won't occur on blood vessels.So, i have to eliminate the candidates which are present on blood vessels and get the output image.Can anyone help me with this?
This is the bood vessel image and the candidate image is below as
I want to remove white dots on candidate image which are present on blood vessels in blood vessels image.
Thank youKrishna Chaitanyahttps://la.mathworks.com/matlabcentral/profile/authors/16691867-krishna-chaitanyatag:la.mathworks.com,2005:Question/4914962019-11-17T00:21:16Z2019-11-18T10:23:50ZError when solving an equation involving a poisson pdfHello, I am trying to find for what values of lambda P(X=10) = 0.1, if X~Po(lambda)
My code is:
syms lambda
solve(poisspdf(10,lambda)==0.1, lambda)
the error I get is:
'error using symengine. Unable to prove 'lambda<0' literally . Use 'isAlways to test the statement mathematically
any help would be much appreciated!
Louis Sharmahttps://la.mathworks.com/matlabcentral/profile/authors/16376749-louis-sharmatag:la.mathworks.com,2005:Question/4916402019-11-18T06:03:25Z2019-11-18T10:22:57Zdivided an audio signal into no. of frames (segments) and Compute mean from each frame (segment) and then how to Concatenate each mean of a frame to obtain one feature vector [y, Fs] = audioread('F:\audio samples\car crashes\(resource)car_crash.wav');
N = length(y); % sample length
slength = N/Fs; % total time span of audio signal
t = linspace(0, N/Fs, N);
figure;
subplot(2,2,1);
plot(t, y); % pplots the audio
duration = round(0.04*Fs); %duration selected from 40 ms, how many samples in a frame
n_f=floor(N/Fs)+1; %how many frames are there
display(n_f);
temp=0; %temporary value
for i= 1: n_f
frames(i,:) =y (temp+1: temp+duration);
temp=temp+duration;
M{i} =mean(frames(i,:));%mean of (n_f) frames
display(M{i});
Mconcat = cat(1,M{i});
display(Mconcat);anusha koduruhttps://la.mathworks.com/matlabcentral/profile/authors/14994531-anusha-kodurutag:la.mathworks.com,2005:Question/4908412019-11-13T11:14:50Z2019-11-18T10:09:38ZPower of white noise set in Simulinkgood morning to all of you,
I should build a kalman filter with simulink and I have to put a white noise in the output. some of you would be able to tell me what relationship between the power noise of the ' band limited white noise block' and the variance of the noise I choose. For example, if the variance of white noise is 3, how much should I set the power noise?SVhttps://la.mathworks.com/matlabcentral/profile/authors/10453735-svtag:la.mathworks.com,2005:Question/4916502019-11-18T06:45:50Z2019-11-18T10:05:56ZAre there any other ways(function) of finding jacobian matrix numerically beside the function numjacAre there any other ways(known function) of finding jacobian matrix numerically beside the function numjac?
basically I am going to input something like x=[x1 x2 x3 .....xn]' into a function such as x'*x and find its jacobian Kevin Linhttps://la.mathworks.com/matlabcentral/profile/authors/5282495-kevin-lintag:la.mathworks.com,2005:Question/4910812019-11-14T13:01:35Z2019-11-18T10:05:02ZCombining a function and solver to create a M-function in SimulinkIf I have the following function and solver script:
The function is:
function dydt = odefcn(t,y,A,B)
dydt = zeros(2,1);
dydt(1) = y(2);
dydt(2) = (A/B)*t.*y(1);
The solver script:
A = 1;
B = 2;
tspan = [0 5];
y0 = [0 0.01];
[t,y] = ode45(@(t,y) odefcn(t,y,A,B), tspan, y0);
How can I combine both to create a "MATLAB function" block in Simulink that takes A and B as input, and outputs y?
Thanks a lot!Wa3idhttps://la.mathworks.com/matlabcentral/profile/authors/15171963-wa3idtag:la.mathworks.com,2005:Question/3910742018-03-27T19:10:19Z2019-11-18T10:04:13ZModeling of PMSM motor in Simulink embedded MATLAB FunctionHi,
I have implemented math model of PMSM motor using simulink blocks (Pic1) and equations (Pic2) of PMSM motor
<</matlabcentral/answers/uploaded_files/110395/SchematSimulink.PNG>>
Pic1
<</matlabcentral/answers/uploaded_files/110397/r%C3%B3wnania.PNG>>
Pic2
I want to implement the same model using embedded MATLAB function block (Pic3)
<</matlabcentral/answers/uploaded_files/110396/MATLABFunction.PNG>>
Pic3
where id_m, iq_m are measured outputs PMSM model currents,
uqIN, udIN are measured outputs PI controller voltage,
omega_m is measured outputs PMSM model angular speed.
*I don't know how to implement integrator in code.*
My suggestion of code is below
function [idOut, iqOut] = EKF(idm, iqm, udm, uqm, omegam)
%dane silnika
Rs = 0.12;
Ld = 0.9e-3;
Lq = 1.05e-3;
Jm = 0.19;
Yf = 0.075;
p = 9;
Tl = 0;
persistent xhat;
if isempty (xhat)
xhat = [0.1; 0.1; 10];
end
xhat(1) = (p * xhat(3) * xhat(1) * Lq + udm - Rs*xhat(2)) * 1/Ld; %id
xhat(2) = (-p * xhat(3) * xhat(2) * Ld - Yf*p*xhat(3)+uqm-Rs*xhat(1))*1/Lq; %iq
xhat(3) = (3*p)/(2*Jm) * (Yf*xhat(2) + (Ld-Lq)*xhat(1)*xhat(2)) - Tl/Jm; %omega
xhat (1) = xhat(1) + idm;
xhat (2) = xhat(2) + iqm;
xhat (3) = xhat(3) + omegam;
idOut = xhat(1)
iqOut = xhat(2)Kuba Wozniakhttps://la.mathworks.com/matlabcentral/profile/authors/11194173-kuba-wozniaktag:la.mathworks.com,2005:Question/4916662019-11-18T10:02:49Z2019-11-18T10:02:49Z2D Matrix revolutionHi community
How can I revolutionize a 2D matrix around an axis to obtain a solid?
Supose a NxN matrix. In each row are the points of a kind of gaussian curve with less amplitude and higher width. Plotting this surface shows something like a half bell that decays to zero. (See Bottom)
I want to obtain a 3D image revolutionazing that matrix, so the solid looks like a complete bell, or a mexican hat.
Notice that each curve in the matrix rows are different.
I have already try with cylinder(), but i can't define the rotation axis, and the result is a segmented solid.
Possible solutions so I can get the 3D image and define the rotation axis?
Thanks a lot
The surface to revolutioniye looks like this:
Cylinder shows this:
Felipe Bayonahttps://la.mathworks.com/matlabcentral/profile/authors/15577547-felipe-bayonatag:la.mathworks.com,2005:Question/4910992019-11-14T15:20:05Z2019-11-18T10:02:15ZData Augmentation not workingHi,
I'm trying to do data augmentation using 'ImageDataAugmenter' on a PixelLabelImageDatastore but the rate of my training is not decreasing (as it should if more images are added).
I'm not getting any error but the my training progress shows the same number of iterations and epochs as my non-augmented dataset.
This is my code:
imageAugmenter = imageDataAugmenter( ...
'RandRotation',[-10,10], ...
'RandXTranslation',[-10 10], ...
'RandYTranslation',[-10 10])
augimds = pixelLabelImageDatastore(imds,pxds,'DataAugmentation',imageAugmenter,'OutputSize',imageSize)
trainedNet_aug = trainNetwork(augimds,lgraph,options)
Does Data augmentation add new images to the datastore? Because it still shows my original 300 images in the augimds variable.Hridayihttps://la.mathworks.com/matlabcentral/profile/authors/7044219-hridayi