https://es.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-11-22T21:44:51Ztag:es.mathworks.com,2005:Question/4926622019-11-22T21:39:48Z2019-11-22T21:44:51ZGenerating random number for the Inverse Gaussian distributionwhat is the code for generating random number for the inverse Gaussian distribution?
Please post here if anyone known of a good method of doing this.Abas Arkawazihttps://es.mathworks.com/matlabcentral/profile/authors/16928889-abas-arkawazitag:es.mathworks.com,2005:Question/4926592019-11-22T21:29:53Z2019-11-22T21:43:17ZI want to change the data type of a table column from double to cellsI want to concatenate two tables with a function (see below) that recognizes common variables appends the values of the second table to the values of the first for all common variables and fills the rest with defaults (typically zeros and empty strings)
The fuction checks for incompatible data types ( sopecifically cells or strings copied to doubles). I can identify the problem variables, but I cannot do anything about it. Is there a way to alter thet data type as in Table.Properties.Datatypes(index) = 'cells'?
Any help is much appreciated,
Ronald
Here is the function
function [T, commonnames] = growtable( T1, T2 )
%function T = growtable( T1, T2 )
% adds all values of table T2 to table T1 for all variablenames these tables have in
%
%%
% get varibale names from both tables
names1 = T1.Properties.VariableNames;
names2 = T2.Properties.VariableNames;
% find the common names
[commonnames,cidx1,cidx2] = intersect(names1,names2, 'stable');
if ~isempty( commonnames )
warning('off')
% Determine how many rows to add
[addrows, ~] = size(T2);
% Determine the row range in T1 needed to append these rows
[nrows, ~ ] = size(T1);
kdo = (1:addrows)+nrows;
% Check for cell copied to double type conflicts
classT1 = varfun(@class,T1(:,cidx1) ,'OutputFormat','cell');
doubles1 = ismember( classT1, {'double'} );
classT2 = varfun(@class,T2(:,cidx2),'OutputFormat','cell');
cells2 = ismember( classT2, {'cell'} );
% Errors ensue when copying cells into a doubles space
problemidx = find( doubles1 & cells2 );
% If is is one we copy we have a problem
if ~isempty( problemidx )
varname = names1( problemidx );
temp = T1{ :, varname };
%%%%% HERE is the problem!!!!!!!!
% How can I force the column of doubles to become a column of
% cells?
T1{ :, varname } = num2cell(temp);
%%%%%%%%%
end
% do the merge into a new output table T
T = T1;
T( kdo, commonnames ) = T2( :, commonnames);
else
fprintf( 2, 'Warning in %s table 1 returned unchanged. Table 2 has no common variables\n', mfilename);
T = T1;
endRonald Ouwerkerkhttps://es.mathworks.com/matlabcentral/profile/authors/7446693-ronald-ouwerkerktag:es.mathworks.com,2005:Question/4926612019-11-22T21:38:49Z2019-11-22T21:38:49ZAttempting to get fminsearch to work. Likely a silly mistake.I am writing code to simulate a double pendulum, whose two natural frequencies (wn) should be 2 and 5hz. I would like to optimize L1 and L2 (arm lengths) with fminsearch in order to bring (wn) to 2 and 5 hz.
My difficulty seems to lie in creating the cost function which is being used with fminsearch. What I have written is my best guess, which currently yields an error.
https://pastebin.com/avzJvQys
In short:
I am attempting to determine L1 and L2 such that wn(1) and wn(2) of the system are 2, and 5 hz respectively, and am having trouble setting up the function that interfaces with fminsearch itself.
Any help would be greatly appreciated. Thank you.Gus Hopkinshttps://es.mathworks.com/matlabcentral/profile/authors/16929020-gus-hopkinstag:es.mathworks.com,2005:Question/4913982019-11-16T06:25:09Z2019-11-22T21:33:45Zhow to contaminate ecg signal with noiseI am working on the project namely "FALSE ALARM REDUCTION IN ATRIAL FIBRILLATION DETCTION USING DEEP BELIEF NETWORKS".
In this i need to download two databases, namely 07910m.mat{MIT_BIH ATRIAL FIBRILLATION DATABASE} which is attached here,and also the 'em' recording {MIT_BIH NOISE STRESS TEST DATABASE} is attached.
The afib database has Fs=250Hz and 10h in length,and 'em' recording is 30 min and has Fs=360Hz
now i need to make the 'em' recording 10h in length
in the paper its told that i can be done using auto regressive model,iam not knowing how to do it
can anyone suggest me the coding for this
sai lakshmihttps://es.mathworks.com/matlabcentral/profile/authors/15911919-sai-lakshmitag:es.mathworks.com,2005:Question/4914432019-11-16T14:39:57Z2019-11-22T21:33:14Zcan i make a loop for mentioned equation?hi everybody;
i want to find the value of (Pb_dis) from below equation and then make a loop to put (Pb_dis) value that i found from equation to (Pb1dis) to find (Pb_dis1) and to put the value of (Pb_dis1) to (Pb1dis) again to find (Pb_dis2) and so on . thank you very much i really appreciate it if you help me,
initial Pb1dis =3600 w
this is the equation:
Pb_dis= (Pb1dis*(1-sigma))-((Ppv/nu_i)-PL);
Mamad Mamadihttps://es.mathworks.com/matlabcentral/profile/authors/14468931-mamad-mamaditag:es.mathworks.com,2005:Question/4926602019-11-22T21:31:25Z2019-11-22T21:31:25ZHow to extract partial derivatives of some specific layer in the back-propagation of a deep learning model?Say I have a deep learning model, and after training I call this model net.
When I input some images into net, I want to have the partial derivatives , where are the outputs of the relu1 layer (i.e. ) and are the parameters of all trainable weights of the layers before relu1.
You can see that (i.e. the output of relu1) will have a size of . I write the size of the training weights before relu1 as , where would be the set of all trainable parameters of the layers before relu1. Therefore should have the size of .
How can I get in the code? Many thanks!
My current code
%% Load Data
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
'nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
numTrainFiles = 50;
[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,'randomize');
%% Define Network Architecture
inputSize = [28 28 1];
numClasses = 10;
layers = [
imageInputLayer(inputSize)
convolution2dLayer(5,20,'Name','conv1')
batchNormalizationLayer('Name','bn1')
reluLayer('Name','relu1')
fullyConnectedLayer(numClasses,'Name','fc2')
softmaxLayer('Name','softmax')
classificationLayer];
%% Train Network
options = trainingOptions('sgdm', ...
'MaxEpochs',4, ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(imdsTrain,layers,options);SChttps://es.mathworks.com/matlabcentral/profile/authors/12071809-sctag:es.mathworks.com,2005:Question/4926582019-11-22T21:27:03Z2019-11-22T21:27:03ZError using fsurf (too many functions) but success using ezsurfWhen using the fsurf command to plot this function, I recieve the message: "error using fsurf, too many functions."
By simply changing "fsurf" to "ezsurf" I successfully get my 4 figures (intended to model tumors).
I understand there is a difference in the plotting methods of fsurf and ezsurf, and I assume that fsurf, if correctly used, would give me more detailed figures. What could be causing the discrepancy? I appreciate any and all help!
syms u v
for a = 3:4
for b = 5:6
figure
fsurf((1+1/5*sin(a*u)*sin(b*v))*sin(v)*cos(u),(1+1/5*sin(a*u)*sin(b*v))*sin(v)*sin(u),(1+1/5*sin(a*u)*sin(b*v))*cos(v),[0 2*pi 0 pi])
end
end
Austin Vander Lindenhttps://es.mathworks.com/matlabcentral/profile/authors/16350528-austin-vander-lindentag:es.mathworks.com,2005:Question/4853162019-10-14T22:01:03Z2019-11-22T21:25:15Zmodify powertrain blockset library controller Hi,
I want to add an additional input to the current controller library block with the lookup tables used. More specifically the blocks below.
SiEngineController (SiEngineController)/SI Controller/Controllers
SiEngineController (SiEngineController)/SI Controller/Estimators
When I unlock the library, the n-D lookup blocks still show locked and disable link is also greyed out. Can anyone tell me the appropriabte way to do this?
Thanks!
ricky Chttps://es.mathworks.com/matlabcentral/profile/authors/2676846-ricky-ctag:es.mathworks.com,2005:Question/4926352019-11-22T18:09:26Z2019-11-22T21:21:42Zadd text to photos please check my code, latest_data(i,j,k)=candidate_Image(i,j,k)-mod(candidate_Image(i,j,k),2)+M(count,1);candidate_Image=('apa.jpg'); %load the image
M = 'rahasia.txt'
rahasia=fopen (M,'rb'); %open secret file
[M,L] = fread(rahasia,'ubit1'); %read secret file as bin array
% L is the length of secret file
[n,m]=size(candidate_Image); %n is width, m is height*3
m=m/3;
%m*n is the max size to save secret
if (m*n*3<L)
msg=msgbox('your picture is too small','size error','modal');
pause (1);
if (ishandle (msg))
close (msg);
end
end
latest_data=candidate_Image;
count=1;
for i=1:m %width
for j=1:n %height
for k=1:3 %RGB
latest_data(i,j,k)=candidate_Image(i,j,k)-mod(candidate_Image(i,j,k),2)+M(count,1);
if count==L
break;
end
count=count+1;
end
if count==L
break;
end
end
if (L==count)
break;
end
end
imwrite(latest_data, 'encrypted_Image.jpg', 'bmp');
CC=M;
countl=l;
for i=l:m
for j=l:n
for k=l:3
CC(countl)=latest_data(i,j,k)-candidate_Image(i,j,k);
if countl==L
break
end
countl=countl+l
end
if countl==L
break
end
end
if countl==L
break
end
endahmad assahabhttps://es.mathworks.com/matlabcentral/profile/authors/16877839-ahmad-assahabtag:es.mathworks.com,2005:Question/4926572019-11-22T21:19:56Z2019-11-22T21:19:56Zsolve ode with parametrizing functionhello i want to solve ode45
function x= teliko(R32y,F43x,R32x,F43y,R12y,F32x,F32y,a3,R23,w3,th3,R23y,R23x,R12x,R12,T12,m2,m3,Ig2,Time)
tspan=[0 0.5]; % set time interval
x0=[0 2 ]; % set initial conditions
[t,x] = ode45(@(t,x) for_kine(R32y,F43x,R32x,F43y,R12y,F32x,F32y,a3,R23,w3,th3,R23y,R23x,R12x,R12,T12,m2,m3,Ig2,Time),tspan,x0);
plot(t,x(:,1))
end
function dzdt = for_kine(t,x, R32y,F43x,R32x,F43y,R12y,F32x,F32y,a3,R23,w3,th3,R23y,R23x,R12x,R12,T12,m2,m3,Ig2,Time)
x1=x(1);
x2=x(2);
T12__=interp1(T12,Time,t);
R12_=interp1(R12,Time,t);
R12x_=interp1(R12x,Time,t);
f12=0;
f14=rad2deg(56.4);
f23=0;
R23x_=interp1(R23x,Time,t);
R23y_=interp1(R23y,Time,t);
w3_=interp1(w3,Time,t);
th3_=interp1(th3,Time,t);
R23_=interp1(R23,Time,t);
a3_=interp1(a3,Time,t);
F32y_=interp1(F32y,Time,t);
F32x=interp1(F32x,Time,t);
R12y_=interp1(R12y,Time,t);
F43y_=interp1(F43y,Time,t);
R32x_=interp1(R32x,Time,t);
F43x_=interp1(F43x,Time,t);
R32y_=interp1(R32y,Time,t);
dzdt = [x(2) ; [x(2)^2*[R12_*m2*[-R12x_*sin(x(1)+f12)+R12y_*cos(x(1)+f12)]+a*m3*[-R23x_*sin(x(1))+R23y_*cos(x(1))]] +...
w3_^2*[R23_*m3*[-R23x_*sin(th3_+f23)+R23y_*cos(th3_+f23)]]+...
a3_*[R23_*m3*[R23x_*sin(th3_+f23)+R23y_*cos(th3_+f23)]]+...
[-F32y]*R12x_+[F32x_]*R12y_+[-F43y_-Fpy]*R32x_+[F43x_+Fpx]*R32y_+T12__]/[Ig2-[R12_*m2*[cos(x(1)+f12)*R12x_+R12y_*sin(x(1)+f12)]+m3*a*[-R32x_*cos(x(1))+R32y_*sin(x(1))]]];];
end
and i get error not enough arguments at T12__=interp1(T12,Time,t);
T12 and time are 1*1001 vector
i think that T12 and Time are not inserted into the functionchristoforos Nicodemouhttps://es.mathworks.com/matlabcentral/profile/authors/13747105-christoforos-nicodemoutag:es.mathworks.com,2005:Question/4926552019-11-22T20:52:57Z2019-11-22T21:13:01ZError using plot Vectors must be the same length.Hi everyone,
I am trying to convolve two step function signals for school assignment the two signals are:
x(t) = (-t+3)(u(t)-u(t-3))
h(t) = 2u(t+2)-u(t+1)
I wrote the code below, when I ran the code I keep getting the "Error using plot
Vectors must be the same length.".the vector generated by the conv command is longer than the t vector!
any help will be appreciated.
clear all
clc
dt=0.01; t= -7:dt:6;
x = 2*heaviside(t+2)-heaviside(t+1);
h =(-t+3).*heaviside(t)-(-t+3).*heaviside(t-3);
y= dt.* conv (x,h);
plot(t,y)
whos
Name Size Bytes Class Attributes
dt 1x1 8 double
h 1x1301 10408 double
t 1x1301 10408 double
x 1x1301 10408 double
y 1x2601 20808 double
these are the values in my work space.Michael Darwishhttps://es.mathworks.com/matlabcentral/profile/authors/2709381-michael-darwishtag:es.mathworks.com,2005:Question/4926162019-11-22T15:13:56Z2019-11-22T21:12:16ZPlot a unit vector in MATLAB, given its starting point and the orientation about 3 axesI have a point [x y z] and the Euler orientation angles [r p y]. How can I plot a unit vector in MATLAB starting from [x y z] in the orientation of [r p y] ?Cris Thomashttps://es.mathworks.com/matlabcentral/profile/authors/8496102-cris-thomastag:es.mathworks.com,2005:Question/4925992019-11-22T13:57:18Z2019-11-22T21:09:53ZHow to remove noise from the signal and identify the peaks for each cycle of the total signalHi everyone,
I have medical data of aorata, In which I want to remove the noise signals and identify the peaks and interference. After that I want to separate the each cycles
from starting point of peak to ending point of the peak for total signal present.
Can any one help me how to proceed on.
Thank you very much for your time.
Lokeswara reddy pamulapatehttps://es.mathworks.com/matlabcentral/profile/authors/13248201-lokeswara-reddy-pamulapatetag:es.mathworks.com,2005:Question/4544652019-04-04T17:05:02Z2019-11-22T21:06:38ZThe application could not connect to MathWorks. For more information on resolving this issue, see this Support Articlei'm trying to install matlab but i keep getting this message [ The application could not connect to MathWorks.
For more information on resolving this issue, see this Support Article ]
i turned off the Antivirus Software and proxy but no luck. please helpKhaled Batainehhttps://es.mathworks.com/matlabcentral/profile/authors/15213641-khaled-batainehtag:es.mathworks.com,2005:Question/3935982018-04-09T08:41:37Z2019-11-22T21:06:31ZWhy do I get the error "Cannot open source file: 'windows.h'" when trying to compile a model Simulink (R2013a)?Hello Users,
I am facing an issue while Compiling my Simulink Model containing ASCII Encode block.
*(F) C0005; "C:\PROGRA~1\MATLAB~1\toolbox\rtw\targets\xpc\target\build\xpcblocks\asciiencode.c", line 20 pos 21; could not open source file "windows.h"
#include <windows.h>
^*
I am not familiar with this situation. Can anyone please help me with this?
Best RegardsSameerhttps://es.mathworks.com/matlabcentral/profile/authors/5204869-sameertag:es.mathworks.com,2005:Question/4923922019-11-21T15:26:44Z2019-11-22T20:57:45ZMatlab 2019b optimoptions not work on sparse jacobPattern anymoreI have just recently update to Matlab2019b, but the optmoptions did not work as I expect.
For example I have sparse jacobian pattern matrix create by A=speye(100000) and feed to optimoption by
'options = optimoptions(@fsolve,'Display','iter','JacobPattern',J,'Algorithm','trust-region','SubproblemAlgorithm','cg');'
It just complain as follows, seems Matlab2019b tries to construct a dense matrix from the sparse. While this code will work on Matlab2018b.
Anyone can help for that, please? ThanksDIZHONG ZHUhttps://es.mathworks.com/matlabcentral/profile/authors/9258347-dizhong-zhutag:es.mathworks.com,2005:Question/4923632019-11-21T12:36:07Z2019-11-22T20:54:27ZUndefined function or variable 'check_Env_Setup'I am trying to program tms320f28335 using simulink
the first problem I am facing is that when I run:
>> checkEnvSetup('ccsv5', 'F28335', 'setup')
I get:
Undefined function or variable 'check_Env_Setup'
the first problem I am facing is that when I run:
>> ticcs
I get
Undefined function or variable 'ticcs'.Hani Sadekhttps://es.mathworks.com/matlabcentral/profile/authors/13031310-hani-sadektag:es.mathworks.com,2005:Question/4926562019-11-22T20:53:13Z2019-11-22T20:53:13ZI have code and I want to draw Flowchart% MRC_scheme.m
% Receiver diversity - MRC
%MIMO-OFDM Wireless Communications with MATLAB¢ç Yong Soo Cho, Jaekwon Kim, Won Young Yang and Chung G. Kang
%2010 John Wiley & Sons (Asia) Pte Ltd
clear, clf
L_frame=1000000;
N_packet=10;
b=4; % Set to 1/2/3/4 for BPSK/QPSK/8QAM/16QAM
SNRdBs=[-10:2:50];
sq2=sqrt(2);
for iter=4:10
if iter==4,
NT=1;
NR=4;
gs='-b^'; % Numbers of Tx/Rx antennas
elseif iter==8,
NT=1;
NR=8;
gs='-mo'; % Numbers of Tx/Rx antennas
elseif iter==16,
NT=1;
NR=16;
gs='-gd'; % Numbers of Tx/Rx antennas
else iter==32,
NT=1;
NR=32;
gs='-ro'; % Numbers of Tx/Rx antennas
end
sq_NT=sqrt(NT);
for i_SNR=1:length(SNRdBs)
SNRdB=SNRdBs(i_SNR);
sigma=sqrt(0.5/(10^(SNRdB/10)));
for i_packet=1:N_packet
symbol_data=randint(L_frame*b,NT);
[temp,sym_tab,P]=modulator(symbol_data.',b);
X=temp.'; % frlg=length(X);
Hr = (randn(L_frame,NR)+j*randn(L_frame,NR))/sq2;
H = reshape(Hr,L_frame,NR); Habs = sum(abs(H).^2,2);
Z=0;
for i=1:NR
R(:,i) = sum(H(:,i).*X,2)/sq_NT + sigma*(randn(L_frame,1)+j*randn(L_frame,1));
Z = Z + R(:,i).*conj(H(:,i));
end
for m=1:P
d1(:,m)=abs(sum(Z,2)-sym_tab(m)).^2+(-1+sum(Habs,2))*abs(sym_tab(m))^2;
end
[y1,i1] = min(d1,[],2);
Xd=sym_tab(i1).';
temp1 = X>0;
temp2 = Xd>0;
noeb_p(i_packet)=sum(sum(temp1~=temp2));
end
BER(iter,i_SNR) = sum(noeb_p)/(N_packet*L_frame*b);
end% end of FOR loop for SNR
semilogy(SNRdBs,BER(iter,:),gs),
hold on,
axis([SNRdBs([1 end]) 1e-5 1e0])
end
title('BER perfoemancde of MRC Scheme employing 16-QAM'),
xlabel('Signal-to-Nosie Ratio (SNR)[indB]'),
ylabel('Bit Error Rate (BER)')
grid on, set(gca,'fontsize',9)
legend('MRC (Nt:1,Nr:4)','MRC (Nt:1,Nr:8)','MRC (Nt:1,Nr:16)','MRC (Nt:1,Nr:32)')
adnan aldakshihttps://es.mathworks.com/matlabcentral/profile/authors/16928870-adnan-aldakshitag:es.mathworks.com,2005:Question/4926362019-11-22T18:14:02Z2019-11-22T20:50:00ZUnable to perform assignment because the because the indices on the left side are not compatible with the right sideHi all,
I had an error regarding assigning values to variables. I was trying to execute a simple program but it always gives me an unable to perform assignemnt error.
A=[ 1,5;2,6;1,5;1,4;3,7;6,5;6,1];
m=7;
for n=1:m
if (A(n,1)== A(:,1))
b(n,1)=find(A(:,1)== A(n,1));
end
end
Can somebody let me know where am I going wrong in this.
Thank you
Rashmi Mohan Kumarhttps://es.mathworks.com/matlabcentral/profile/authors/12260533-rashmi-mohan-kumartag:es.mathworks.com,2005:Question/4925612019-11-22T10:28:35Z2019-11-22T20:48:30ZIs there a way to extracted histogram data into a matrix instead of graph?Hello,
Is there a way to extract histogram data into a matrix instead of a graph?
for mer= start:Add:N_Mer
FileName_1 = ['Info_',num2str(N_Mer),'.mat'];
disp([FileName_1,' Running'])
M=load(FileName_1);
all_rows=cell2mat(struct2cell(M));
R_sqr{N_Mer}=all_rows(1,:);
FileName=(['hist_R2',num2str(N_Mer)]);
hist_R2{N_Mer}=histogram(R_sqr{N_Mer});
legend
hold on
endSomahttps://es.mathworks.com/matlabcentral/profile/authors/11270574-somatag:es.mathworks.com,2005:Question/4926542019-11-22T20:46:36Z2019-11-22T20:46:36ZHow to show msbackadj plot within app window.Hello Everyone,
Recently I have been attempting to make a graphic user interface (GUI) for some of the scripts previously written by one of the grad students in our lab to make it easier for students who don't have experience with editing code to use. One of the scripts is for correcting the baseline of our Raman data, for this he used the built-in msbackadj function. Now this works fine as is but to keep everything neat and tidy I've been trying to keep everything within the main app window, I have two graphs in the app to handle any of our plots, and I'm not sure how to put the plot of msbackadj into one of these windows instead of spawning its own figure window.
I've included my code for the Baseline correction button but the only really important part there is the
ICorr = msbackadj(app.Pixel2,app.I2,'WindowSize',app.window,'StepSize',app.step,'Showplot',true);
line. Setting Showplot to true pulls up a separate figure window showing the plot of Pixel2 and I2 alongside what is being subtracted from that plot. I'd like to put all of this into the UIAxes that I have on the main app window.
Any assistance or advice anyone has would be greatly appreciated. Thanks in advance.
% Button pushed function: BaselineCorrectionTestButton
function BaselineCorrectionTestButtonPushed(app, event)
%Adjust the "Window Size" and "StepSize" until you achieve a baseline
%correction which looks good. Use these values in "BaselineCorrAll"
%Note: Baseline correction must be done BEFORE calibration
ICorr = msbackadj(app.Pixel2,app.I2,'WindowSize',app.window,'StepSize',app.step,'Showplot',true);
%Plot the baseline corrected data next to the original.
% figure;
plot(app.UIAxes2, app.Pixel2, app.I2);
hold (app.UIAxes2, 'on')
plot (app.UIAxes2, app.Pixel2, ICorr);
hold (app.UIAxes2, 'off')
endHal Bowen-Smithhttps://es.mathworks.com/matlabcentral/profile/authors/16734606-hal-bowen-smithtag:es.mathworks.com,2005:Question/4926462019-11-22T19:29:21Z2019-11-22T20:46:16ZNested for loop for beta and nuSo for this problem we were to create a function called SIRode that has 4 inputs and 1 output. The outputs were time t, state y, beta and nu and the output was ydot.
so i created that function to call in the script using the ODE45.
But for beta and nu we have to create a nested for loops to investigate how different values for the parameters beta and nu afftect the simulation results.
use beta values of 0.005 and 0.05 and nu values of 0.02, 0.04, 0.06 and 0.08 and 0.1 for a total of 10 combinations.
Now I dont understand how to construct this nested loop so my ode45 reader puts the beta and nu each time so i can plot each different one.
attached i have my script and funciton file so far.
Thanks for looking at it for me.
brianna robertohttps://es.mathworks.com/matlabcentral/profile/authors/16127514-brianna-robertotag:es.mathworks.com,2005:Question/4926532019-11-22T20:40:19Z2019-11-22T20:40:19ZDeploying the R-CNN Detector to RaspberryHi,
I am looking the way for deploying pre-trained R-CNN detector to raspberry
Best,Abdussalam Elhanashihttps://es.mathworks.com/matlabcentral/profile/authors/15843739-abdussalam-elhanashitag:es.mathworks.com,2005:Question/4926492019-11-22T20:07:10Z2019-11-22T20:38:56Zproblem to add border between 9 image
close all;
a = imread('image1.jpg');
b = imread('image2.jpg');
f = imread('image3.jpg');
g = image('image4.jpg');
h = image('image5.jpg');
[y,x,c]= size(a);
c = uint8(zeros(y,
c = (:,:,1)= 255;
c = (:,:,1)= 255;
c (:,:,1)= 255;
d =[a,c,b];
imshow(d);
d =[a,c,b,c,f];
imshow(d); ABDULLAH NIAZhttps://es.mathworks.com/matlabcentral/profile/authors/16928639-abdullah-niaztag:es.mathworks.com,2005:Question/4926522019-11-22T20:30:15Z2019-11-22T20:30:15ZI need code to find position of an object using binocular stereo vision We need it to write code to pick red tomato from plant using robotic arm, we place two cameras on moving chassis and we know the distance between them and we got code for detection of tomato
We just need to find position of tomato using binocular stereo vision Imran Yhttps://es.mathworks.com/matlabcentral/profile/authors/16493459-imran-ytag:es.mathworks.com,2005:Question/4925352019-11-22T07:41:55Z2019-11-22T20:29:32ZDoes CCaller block recognize keyword "_inline"?Hi,
I'm currently working on a Simulink blockset including C-Code. I am using CCaller blocks to call the functions of my excisting C-Code.
My problem is, that there are some functions, defined with _inline in my code and the CCaller block seems to not recognize them as defined. Is there a way to include this functions anyway?
Thank you for your answers,
ChantalChantal Ferdianndhttps://es.mathworks.com/matlabcentral/profile/authors/16104027-chantal-ferdianndtag:es.mathworks.com,2005:Question/4380012019-01-02T20:01:27Z2019-11-22T20:29:13ZManually determining the gradient of a surfaceHi , I’m trying to write a function that can manually determine the gradient of a surface (represented by a multivariable function that I have created) at a particular point (x,y)
The code I've written is shown below.
function [pdx,pdy] = comp_gradient(x,y)
kernelx = [2.5,0,-2.5];
kernely = [2.5;0;-2.5];
z = cos(x/2).* cos(y) + (y/10) - (x/5);
pdx = conv2(kernelx,z,'same');
pdy = conv2(kernely,z,'same');
end
I'm not sure where to go from here, my output is clearly incorrect.
Any help would be greatly appreciated.Carlos Pedrohttps://es.mathworks.com/matlabcentral/profile/authors/14439966-carlos-pedrotag:es.mathworks.com,2005:Question/4926512019-11-22T20:21:53Z2019-11-22T20:27:26ZUnderstanding standard deviation codeHi Guys,
For the following built in matlab function for standard deviaion std(X,0,2) please can someone tell me what the 0 and 2 are for?
Thanks in advaceJack Ellishttps://es.mathworks.com/matlabcentral/profile/authors/14908181-jack-ellistag:es.mathworks.com,2005:Question/4926302019-11-22T16:43:24Z2019-11-22T20:23:25ZERROR : "Input arguments must be convertible to floating-point numbers"Hi everyone, im getting this error:
Error using sym/min (line 98)
Input arguments must be convertible to floating-point numbers.
Error in advencedconcrete32a (line 16)
tension= min(Es*(d-c)/c*epscm*As/1000,fy*As/1000);
i guess the problem is that i use "c" before i solved it, how else can i find "c" from the equation compression= tension?
please help.
thank you very much.
b=300; %mm
d=400; %mm
fc=40; %Mpa
Ecm=22*(fc/10)^0.3*10^3; %Mpa
Es=200000; %Mpa
As=2400; %mm^2
fy=400; %Mpa
epsc1=min(2.8/1000,0.7*fc^0.31/1000);
epscu=3.5/1000;
k=1.05*Ecm*epsc1/fc;
epscm=1.5/1000;
syms c
funC=@(epsc) (k*epsc/epsc1-(epsc/epsc1).^2)./(1+(k-2)*epsc/epsc1);
compression= b*fc*c./epscm*integral(funC,0,epscm)/1000;
tension= min(Es*(d-c)/c*epscm*As/1000,fy*As/1000);
solc= compression==tension;
c=solve(solc,c)Shimon Katzmanhttps://es.mathworks.com/matlabcentral/profile/authors/16878416-shimon-katzmantag:es.mathworks.com,2005:Question/4926472019-11-22T19:48:51Z2019-11-22T20:17:17ZFinding the shortest path in a cell array based on given inputIf I have a call array of n - 1x2 vectors, how do I find the shortest path using a combination of these n vectors based on a given input
example using 6 vectors:
existing cell array - { [0 1], [1 2], [2 3], [3 4], [0 3], [1 4] }
input - [0 4]
expected output - {[0 1], [1 4]} or {[0 3],[3 4]}
edit: fixed inputShawn Castelinohttps://es.mathworks.com/matlabcentral/profile/authors/16019075-shawn-castelinotag:es.mathworks.com,2005:Question/4926392019-11-22T18:45:49Z2019-11-22T20:13:43ZHow to read table with specific word in nameHi there,
I have a folder full of .dat files. Many of these .dat files have the word "fluxall" in them, for example "PJG_2019_fluxall.dat". I would like to use the "readtable" function to read all the .dat files with the word "fluxall" in them. So far I have:
files = struct2cell(dir('*fluxall*.dat'));
filenames = char(files(1,:));
ind = cellstr(1:length(filenames));
for i = 1:length(filenames)
eval(['Table_',ind{i},' = readtable(',filenames{i},');']);
end
The idea is to create a table named "Table_1,2,3..." for each "fluxall".dat file. Obviously it doesnt work.
Thanks!Devon Fisher-Chavezhttps://es.mathworks.com/matlabcentral/profile/authors/11238109-devon-fisher-chaveztag:es.mathworks.com,2005:Question/4921072019-11-20T11:57:43Z2019-11-22T20:12:43ZHow 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://es.mathworks.com/matlabcentral/profile/authors/5181076-joshua-abamtag:es.mathworks.com,2005:Question/4926502019-11-22T20:12:00Z2019-11-22T20:12:00ZI need code to find position of an object using binocular stereo vision We need it to write code to pick red tomato from plant using robotic arm, we place two cameras on moving chassis and we know the distance between them and we got code for detection of tomato
We just need to find position of tomato using binocular stereo vision Imran Yhttps://es.mathworks.com/matlabcentral/profile/authors/16493459-imran-ytag:es.mathworks.com,2005:Question/4926412019-11-22T18:52:08Z2019-11-22T20:07:53ZAccessing ROI objects in GUIDEI'm allowing the user to create a series of line ROIs like so, using a GUIDE app pushbutton:
function pushbuttonline_Callback(hObject, eventdata, handles)
% hObject handle to linebtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h = drawline(handles.axes1);
But how can I access these later on in the code?
I was thinking of placing the drawline variables in a global array, but is there a better way of doing this?
Also, if the user deleted a line using the GUI, would the line variable also be removed?
Thanks in advance.John Disandolohttps://es.mathworks.com/matlabcentral/profile/authors/15963540-john-disandolotag:es.mathworks.com,2005:Question/4926482019-11-22T19:55:24Z2019-11-22T19:55:24ZImellipse ROI not resizing in MATLAB GUIDE (2017b)I want to select a circular ROI in a set of image axes in a GUIDE GUI.
The following test code works as expected:
%% Clear the workspace
clear all
close all
clc
fclose('all');
%% Read a standard test image and display it
x = imread('pout.tif');
hf = figure;
ha = axes(hf);
imshow(x);
%% Initialise a circular ROI, allow it to be moved and re-sized, then save the resulting binary mask
x0 = 40;
y0 = 40;
wd = 60;
ht = 60;
Start = [ x0, y0, wd, ht ];
he = imellipse(ha, Start);
setResizable(he, true);
setFixedAspectRatioMode(he, true);
he.Deletable = false;
Venue = wait(he);
BW = createMask(he);
x(~BW) = 0;
imwrite(x, fullfile(pwd, 'ROI.png'));
delete(he);
delete(ha);
delete(hf);
I get the result:
However, the ROI remains fixed at its original size if I attempt the same thing in my GUIDE project. I can move it and double-click to finish, but although there are 4 visible grab handles (NE, NW, SE, SW), I can't resize the circle. The only material change is:
HE = imellipse(handles.ImageDisplayAxes, Start);
I am using 2017b under W10 on a well-specified Dell Precision workstation. Please advise: it is so odd that stepping into GUIDE causes this very simple code to misbehave.Pawel Tokarczukhttps://es.mathworks.com/matlabcentral/profile/authors/3901508-pawel-tokarczuktag:es.mathworks.com,2005:Question/4926442019-11-22T19:10:59Z2019-11-22T19:49:33ZHow to concatenate cell array without causing nested cell arrayI have a matrix years = [2007 2008 2005 2006 2007 2008 2005 2006 2007 2008]. I want to make it a cell array like this years_cell = { [2007 2008] ; [2005 2006 2007 2008] ; [[2005 2006 2007 2008] }. But what I got was 2x1 nested cell array with the first cell as another 2x1 cell array. Thank you for the help in advance guys. Here is my code: Nhut Ngohttps://es.mathworks.com/matlabcentral/profile/authors/15999355-nhut-ngotag:es.mathworks.com,2005:Question/4926432019-11-22T19:05:54Z2019-11-22T19:47:32ZSolving difficult trigonmetric equations for theta. First, thank you for taking the time to read my problem. I apprecaiate any help.
Trying to find roots of the below equation. It doesn't seem to work on octave. When I use an online tool like wolframalpha, I can get the asnwer that I am looking for. I can always approximate the answer graphically but I am interested in the code to cruch answers directly. The below is the input and output. There are roots to my problem. I'm not sure why Matlab can't solve for them. The larger picture problem that I am working on is in finding vertical tangent lines to polar equations which I have done on paper but would like to code.
solve(-1*sin(x)*(4 + 2*cos(3*x + 21*3.14/6)) - cos(x)*6*sin(3*x + 21*3.14/6) == 0,x)
ans = {}(0x0)
Interestingly enough, when I do a simple example like the below, I get the obvious solution. So, I know that "solve" at least works with simple examples:
solve(sin(x) == 0,x)
ans = (sym 2×1 matrix)
⎡0⎤
⎢ ⎥
⎣π⎦
Gabriel Schneckhttps://es.mathworks.com/matlabcentral/profile/authors/6174614-gabriel-schnecktag:es.mathworks.com,2005:Question/4926452019-11-22T19:28:32Z2019-11-22T19:30:44ZUndefined function 'niftiread'I run the matlab function in Termianl which contains the "nitifread", but it failed and showed that "Undefined function 'niftiread' for input arguments of type 'char'."
Here is my matlab function and error warning.
Yunruo Nihttps://es.mathworks.com/matlabcentral/profile/authors/15669304-yunruo-nitag:es.mathworks.com,2005:Question/2450352015-09-25T12:56:38Z2019-11-22T19:30:27Zhow to make comments *not* wrap?how to make comments *not* wrap?
or alternatively, how can i move this annoying vertical gray line that insists on wrapping my comments to the next row? My code can have >80 characters/per line, must i always have this line through the middle of my code? Jacob Graysonhttps://es.mathworks.com/matlabcentral/profile/authors/6761576-jacob-graysontag:es.mathworks.com,2005:Question/4926072019-11-22T14:23:14Z2019-11-22T19:23:56ZOnly plot the contour that satisfies a conditionHi all,
I am sorry if a similar question was asked elsewhere but I couldn't find anything on this so far. So let me describe you my problem and what I've tried so far.
I am using FEMM to solve a magnetic problem. I extract a region of interest from the solved problem in this format x,y,B1,B2; where x are the radial coordinates. B1 is the magnetic field along x, y is the longitudinal coordinate and B2 is the field along y. I then import this data and reshape the array so it matches the shape of the region of interest. I then calculate |B| and then calculate the frequency from |B|. for a 2x8 inch surface I got an array of a size 200x800. Then I plot the contour for the entire range of frequencies. Which is around Z=4 inches and r = 0
I am observing which area is the most homogenous and then asign an approximate value for this frequency. Then I am looking for values that are +/- 0.005 this frequency by using the find function. After I get the x,y coordinates for these frequencies I use these indexes and place them into another array with columns x, y, freq. Then plot r against Z and get this. It's great but I am not seeing the line at higher r values.
This is what I would sort of expect, a third curve which is in black.
What I tried is to get the condition for freq +/- 0.005 and whichever value does not satisfy this condition to set all the values to 0. This gives me funny things.
Now enough of this let me add in some code.
p = 5/1e3; % precision
z_ref = 2; % reference position
freq = 2.62% frequency in the homogenous region
%importing data
data_import=csvread([imp_datapath + filename1]);
rscale_org = data_import(:,1);
zscale_org = data_import(:,2);
B1(:,1) = data_import(:,3);
B2(:,1) = data_import(:,4);
%calculating B modulo
B = sqrt(B1.^2+B2.^2);
%info about the area of interest
x1 = 0; x2 = 2; dx =0.01;
y1 = 2; y2 = 10; dy=0.01;
ni = (x2-x1)/dx;
nj = (y2-y1)/dy;
%reshaping data
Bgrid = reshape(B, ni, nj)';
rscale_1 = reshape(rscale_org ,ni, nj);
zscale_1 = reshape(zscale_org, ni, nj);
rscale(1,:) = rscale_1(:,1);
rscale_min = rscale .*-1;
zscale = zscale_1(1,:);
zscale_r(1,:) = zscale(1,:) - z_ref;
%calculating frequency from |B|
Fgrid = Bgrid .* 42.576;
%first plot as shown above
figure(1)
contour(rscale,zscale_r,Fgrid,linspace(1, 10, 100))
hold on
contour(rscale_min,zscale_r,Fgrid,linspace(1, 10, 100))
hold off
xlabel('R, [inch]');
ylabel('Z, [inch]');
title('NMR frequency, symmetric about R = 0');
colormap([0 0 0])
axis equal
axis([-2 2 0 8])
[z_direction, r_direction] = find((Fgrid<=(freq+p))&(Fgrid>=(freq-p)));
n = size(z_direction);
for i = 1 : n(1,1)
%grid_c format [r z freq]
grid_c(i,1) = rscale(1,r_direction(i,1));
grid_c(i,2) = zscale_r(1,z_direction(i,1));
grid_c(i,3) = Fgrid(z_direction(i,1),r_direction(i,1));
end
%the second plot as shown above
figure(2)
plot(grid_c(:,1),grid_c(:,2), 'b*')
xlabel('R, [inch]');
ylabel('Z, [inch]');
for i = 1 : nj
for j = 1 : ni
if ((Fgrid(i,j)>freq-p)&(Fgrid(i,j)<freq+p))
FfFF(i,j)=Fgrid(i,j);
else
FfFF(i,j)=0;
end
end
end
%this plot only shows contours where there are continuous lines
figure(3)
contour(rscale,zscale_r,FfFF,linspace(freq+p,freq-p,10))
hold on
contour(rscale_min,zscale_r,FfFF,linspace(freq+p,freq-p,10))
hold off
xlabel('R, [inch]');
ylabel('Z, [inch]');
title('NMR frequency, symmetric about R = 0');
colormap([0 0 0])
axis equal
axis([-2 2 0 8])
So my question is. Does anyone have an ideea how I could get a contour plot similar to the one I showed you above with the black line on it?
Thanks in advance!
Best wishes,
Ors.
P.S.: I edited the post and I uploaded the data2.csv which contains the data. Maybe it helps.Örs Istokhttps://es.mathworks.com/matlabcentral/profile/authors/11883202-ors-istoktag:es.mathworks.com,2005:Question/4926422019-11-22T19:00:39Z2019-11-22T19:20:54ZI need code to find distance of an object using binocular stereo vision I need it for robotic arm control Imran Yhttps://es.mathworks.com/matlabcentral/profile/authors/16493459-imran-ytag:es.mathworks.com,2005:Question/4921822019-11-20T17:35:10Z2019-11-22T19:18:51ZAverage of Wave from 10 waves in single graphHello Everyone,
I Have a doubt regarding the average of the wave from a set of waves from sinlge dataset. I need to get a single average curve from all these curves from the figre. I am new to matlab and cannot figure it out aCnd have been trying since last few days but iam not unable to do so. I need you help and it would be great for me. Thanks in advannce.Lokeswara reddy pamulapatehttps://es.mathworks.com/matlabcentral/profile/authors/13248201-lokeswara-reddy-pamulapatetag:es.mathworks.com,2005:Question/4926252019-11-22T16:28:06Z2019-11-22T19:17:42ZRead text file with multiple rows of fieldsI am trying to read in a large text file with a challenging formatting. Instead of one long row of many fields, the file is broken into chunks with multiple rows of fields. Additionally, the headers repeat every so often and at an inconsistent rate. I've attached an example. I am trying to find a way to efficiently read in the data and organize it so that each field is a single array in a struct/cell/table/etc. The best I can think of is just to go line by line, knowing how many rows are in each block, and detect when I've encountered headers.David Khttps://es.mathworks.com/matlabcentral/profile/authors/5207775-david-ktag:es.mathworks.com,2005:Question/4926222019-11-22T16:13:22Z2019-11-22T19:10:15ZI would appreciate some assistance on some coding. The goal is to create this image:
It is a 2-dimensional array made of ones (size 100x100), and I need to set up a single 'for' loop with 100 iterations from row 1 to row 100, applying conditional statements inside the loop to generate the binary image.
There may be various ways to go by achieving my goal, the path I have chosen consists of me gathering all the points, and thus filling in the points.
Image below to show my progress:
So this led me to think of two questions. 1) Is it even possible for me to "fill" the points, and 2) Is there a better way to do this, and if so, could anyone supply me with the neccesary coding required?
Thanks. (p.s, this is being done on R2019A, but R2019B works just fine too)Arslan Ahmedhttps://es.mathworks.com/matlabcentral/profile/authors/16786396-arslan-ahmedtag:es.mathworks.com,2005:Question/4925752019-11-22T11:32:54Z2019-11-22T19:09:57ZMatrix multiplication using multicorehow can i multiply a matrix of dimension (2^18*103) by its transpose using multiple cores of my local system ?ANUSAI Rhttps://es.mathworks.com/matlabcentral/profile/authors/16586480-anusai-rtag:es.mathworks.com,2005:Question/4925122019-11-22T04:32:20Z2019-11-22T19:08:54ZInsert Interpolation Into Matlab CodeHi, I am new to Matlab programming. The graph result should be have a range of x-asix from -1 to 1, but now the graph is from 0 to 1. I want to set the range for x-axis from -1 to 1. May I know anyone can help me?
This is the current program code.
This is my current result:
Thanks in advance!KIEN WEI LAIhttps://es.mathworks.com/matlabcentral/profile/authors/16921950-kien-wei-laitag:es.mathworks.com,2005:Question/4925542019-11-22T10:05:05Z2019-11-22T19:00:32ZMemory usage very highI always have problems with matlab (R2019b) using too much memory (way more than the variables I have saved). Currently I'm running a function to extract data from a number of structures. I paused the function because the level of RAM being used just doesn't make any sense. Task manager says that Matlab is using 4.7gb of memory, even though I'm not running anything right now. The total size of all the variables in my workspace is ~0.055gb and I have no figure windows open. The only two programs I have running on my computer are Matlab and Task Manager. Is there any reason that Matlab would be using so much memory and is there a way for me to reduce it?
Julia Rhyinshttps://es.mathworks.com/matlabcentral/profile/authors/8781617-julia-rhyinstag:es.mathworks.com,2005:Question/4926122019-11-22T14:56:21Z2019-11-22T18:58:41ZHow can I import data in a range beyond 24 hours in MATLAB?Hello all,
I am trying to analyze some data in MATLAB, and for this it is necessary to import it.
But when I try to import the data into the Datetime format, MATLAB only accepts times until 24h.
I tried to change between hh:mm:ss.sss and HH:mm:ss.sss but the problem only changes from 12h and 24h.
Below you can see how MATLAB identifies the data and the code.
Can you please tell me what can I do?
Thank you in advance!
BRGustavo Cerverahttps://es.mathworks.com/matlabcentral/profile/authors/16926825-gustavo-cerveratag:es.mathworks.com,2005:Question/4921202019-11-20T13:05:43Z2019-11-22T18:56:32Ztable editing and excel exportHello,
I don't know Matlab well yet and can't get any further.
I get from an analysis of a Matlab program the results as a table, which I want to edit in Matlab and export to Excel.
Time Value1 Value2 ...
1.0 27832.2 129819.2 ....
... ...
After the first line, I would now like to insert 2 more lines. One line should contain the unit and the second line should contain a comment (2 of the test parameters).
In addition, a variable is to be added after each heading ( Value1 - Sample1, Value2 - Sample1...).
The table is then to be exported into an Excel table. The name should consist of the experiment data ( Sample1_date.xls). The two variables are read in at the beginning of the program.
Then a second Excel table is to be exported in which the data of the Value1-Value10 columns are converted with a conversion factor.
Can anyone help me?
Sorry for my bad english, I hope it's understandable. Ceshihttps://es.mathworks.com/matlabcentral/profile/authors/15523631-ceshitag:es.mathworks.com,2005:Question/4926372019-11-22T18:32:33Z2019-11-22T18:52:05ZHow can i find number in array? Help me !i have 3 arrays s,d and w
s and d to the starting and ending points
and w to the distance between point and another point
when i run the code i'm entring a point of starting and ending
and i want when i input the starting points i get all that paths that lead to another point
example :
w=[17 5.9 5.7 9.1 7.6 6.2 6.4 20.7 6.5 20 7.5 2.2 3.6 3.7 27.4 0.4 8.2];
s=[1 1 1 1 1 1 7 4 7 3 7 6 4 3 6 4 7];
d=[2 3 4 5 6 7 4 2 3 2 6 5 5 5 2 3 5];
DG= sparse([s],[d],[w]);
ug=graph(DG'+DG);
figure(2);
p=plot(ug);
highlight(p,ug,'NodeColor','red');
s= inputdlg ('input the start node :');
d= inputdlg ('input the end node :');
num1=s;
num2=d;
if isequal(s,d)
e=0;
disp(e);
L=[s];
disp(L)
else
I = find(DG(num1,d,w));
disp(I)
end
end
Asma Shttps://es.mathworks.com/matlabcentral/profile/authors/16807465-asma-s