https://jp.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — 新規の質問2018-12-15T12:25:27Ztag:jp.mathworks.com,2005:Question/4358842018-12-15T12:23:31Z2018-12-15T12:25:27Zhow to transmit data serially from Raspberry Pi to Arduino through USB cable?Basically, my objective is to: Take a snapshot from an USB camera connected to Raspberry Pi and detect a particular object and followed by some calculations, serially transmit a 1x3 vector to Arduino Uno through USB cable.
Now , I created two models, one is to serially transmit the data from Raspberry Pi, while the other is used to serially receive the data and to flag the led on/off. These models were deployed to their respective hardwares, but I was unable to get the results. Please help me to fix this problem. I have attached both the Simulink models with this question.
Also, do I need to connect the two boards ground and vcc pins(through voltage divider bridge) together for this?
Omkar Bhanaphttps://jp.mathworks.com/matlabcentral/profile/authors/9528744-omkar-bhanaptag:jp.mathworks.com,2005:Question/4358832018-12-15T12:18:14Z2018-12-15T12:23:36ZIs there an Optimization Tool that returns a function?Hey:)
So this is my problem:
I want to maximize the final mass of an ascending rocket into an orbit by controlling the trajectory over a thrust vector control variable a(t). So I need an Optimization Toolbox that returns me the optimal function a(t), but the objective function I want to minimize is m(t). And I couldn't find anything about this anywhere. I tried for example fmincon, but fmincon only returns a scalar.
Do you have any ideas?
Brendan Görreshttps://jp.mathworks.com/matlabcentral/profile/authors/13254816-brendan-gorrestag:jp.mathworks.com,2005:Question/4358212018-12-14T19:00:02Z2018-12-15T12:23:25ZCan't seem to figure out how to begin on this project: Drawing circular shapes from a function that is created by connecting points.This seems like a very difficult project and I've been having trouble with this problem for a very long time. Can anybody help me figure out how to do this?
Sarjeel Zamanhttps://jp.mathworks.com/matlabcentral/profile/authors/11568309-sarjeel-zamantag:jp.mathworks.com,2005:Question/4358822018-12-15T12:15:30Z2018-12-15T12:15:30ZHow can I get the subfolders to expand?Hello, I am trying to select a folder and set that folder as a root node of a graphical tree so as to be able to open the subfolders of the tree recursively. I am using:
tree= uitree ('v0', 'Root', uigetdir, 'Parent', []);
I am able to select a folder and it is set as the rootnode. When I click on the folder it opens and all the files and subfolders appear, however I am unable to open the subfolders. Whenever I click on the + to the left of the subfolders the + just disappears. Is there a way to solve that?
Any help appreciated. Thank you.Fatima Mansourhttps://jp.mathworks.com/matlabcentral/profile/authors/13764834-fatima-mansourtag:jp.mathworks.com,2005:Question/4358812018-12-15T11:54:14Z2018-12-15T12:07:33ZCalling multiple outputs from a function in a loopI am trying to call multiple outputs from a function in a for loop. The code I tried initially is below
for i =1:tsteps
[tnewfin1 (:,i+1),crfin1(1,i)] = newtstep (tnewfin1 (:,i));
end
However I constantly received the error "Invalid use of operator".
I changed it to the following,
for i =1:tsteps
[tnewfin,crfin] = newtstep (tnewfin1 (:,i));
tnewfin1 (:,i+1) = tnewfin
crfin1(1,i) = crfin
end
which worked, despite not really changing what is happening.
I thought the first one would work because initially, when I just wanted one output from the function, the following code ran succesfully
for i =1:tsteps
tnewfin1 (:,i+1) = newtstep (tnewfin1 (:,i));
end
Why would it work to call one output but not two, or why is the first scenario an "invalid use of operator"?Samuel Newallhttps://jp.mathworks.com/matlabcentral/profile/authors/14033696-samuel-newalltag:jp.mathworks.com,2005:Question/4357852018-12-14T15:23:12Z2018-12-15T12:02:21ZHow to acieve a scatter plot like this.Hi I have to do a scatter plot where each point in e.g. the xy-plane consist of determined value. My question is how do i plot a discrete amout of values where each of the values is related to a x, y-coordinate. I have seen reports with plots similar to the one presenten in the picture:
Hope to hear your input.
Best regards.Andreas Christensen Sørensenhttps://jp.mathworks.com/matlabcentral/profile/authors/5642231-andreas-christensen-sorensentag:jp.mathworks.com,2005:Question/4358802018-12-15T11:44:42Z2018-12-15T11:49:42ZChange the output Y-labels in a figure of a multi-output dynamic system
I don't know how I can change the names of the Y-labels out(1), out(2), out(3) and out(4) in this multiplot figure...thomas michielshttps://jp.mathworks.com/matlabcentral/profile/authors/7632051-thomas-michielstag:jp.mathworks.com,2005:Question/1024822009-06-27T01:11:00Z2018-12-15T11:43:21ZWhy does REGEXPREP return an answer different from what I expect when I use space in the replacing pattern?If I enter the following at MATLAB Command Prompt:
res=regexprep('ZZZABAB','^[^A]*A','Q')
the result is QBAB.
If I then enter
res=regexprep('ZZZABAB','^[^A]*A','')
the result is B. I expect the result to be BAB.MathWorks Support Teamhttps://jp.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:jp.mathworks.com,2005:Question/4358772018-12-15T11:13:36Z2018-12-15T11:42:41ZArray is filled incorrectlyI have to calculate the approximate value of the integral using taylor expansion. It is also necessary to calculate the number of required terms and the elapsed time for different accurancy. But arrays are filled incorrectly. As for the number of terms, the first value is calculated correctly, but then the entire array is filled with this value. What's wrong?
syms x;
func = cos(x^2);
a = 0;
b = 0.5;
id = true;
k = 1;
acc_array = [10^(-10) 10^(-9) 10^(-8) 10^(-7) 10^(-6) 10^(-5) 10^(-4) 10^(-3)];
time = [0 0 0 0 0 0 0 0];
terms_number = [0 0 0 0 0 0 0 0];
start = cputime;
for i = 1:8
while (id)
taylor_series = taylor(func, x, 'Order', k);
terms = children(taylor_series);
if (terms~=0)
for j = 1:length(terms)
terms_int = int(terms(j), [a b]);
if (abs(terms_int)<=acc_array(i))
id = false;
end
k = k + 1;
end
end
end
terms_number(i) = length(terms);
if (i > 1)
time(i) = cputime - time(i-1);
else
time(i) = cputime - start;
end
end
time
terms_number Valentin Shchepetovhttps://jp.mathworks.com/matlabcentral/profile/authors/14273224-valentin-shchepetovtag:jp.mathworks.com,2005:Question/4358792018-12-15T11:36:26Z2018-12-15T11:36:26ZSchool project - Fourier TransformHey everyone, i have a school project to do and i need some help
Thing we should do is: We should do a fourier transform of a photo. We should only use a 1/3 of values to draw that picture. And the outcome has to be the original photo and next to it a photo approximated by fourier basis.
Any ideas how to do this ?Vincent Sinhttps://jp.mathworks.com/matlabcentral/profile/authors/13709665-vincent-sintag:jp.mathworks.com,2005:Question/4358752018-12-15T11:00:56Z2018-12-15T11:34:02ZHow can I convert an array of hex values to a num?
I have an array with '30' '2E' '30' '31' for example, it is a part of a xbee frame, so I would like to get the value (0.01) and I do not know how... Maybe hex2num? But i dont knoe how to insert the values on it.
I know how to do the oposite operation:
>>dec2hex('0.01')
4×2 char array
'30'
'2E'
'30'
'31'
Please help, I'm trying everything...Alejandro Jimenezhttps://jp.mathworks.com/matlabcentral/profile/authors/9681067-alejandro-jimeneztag:jp.mathworks.com,2005:Question/4358662018-12-15T07:56:57Z2018-12-15T11:31:28ZHow can I store dates as arrays for further process when using Matlab GPU computing?In the following attached code, I would like to record the variable Z in the while loop as array for further process, for example, finding the max value of Z in the array. But the dynamic array is not supported in the arrayfun for GPU computing. How to solve this problem?
function test_GPU_computing
maxIterations=500;
gridSize=1500;
xlim=[-0.75, -0.73];
ylim=[ 0.12, 0.14];
t=tic();
x=gpuArray.linspace( xlim(1), xlim(2), gridSize );
y=gpuArray.linspace( ylim(1), ylim(2), gridSize );
[xGrid,yGrid] = meshgrid( x, y );
count=arrayfun( @tar_fun,xGrid, yGrid, maxIterations );
count=gather(count);
gpuArrayfunTime=toc(t)
figure(3)
imagesc(x,y,count)
reset(gpuDevice(1))
function count=tar_fun(x0,y0,maxIterations)
z0=complex(x0,y0);
z=z0;
count=1;
while (count <= maxIterations) && (abs(z) <= 2)
count=count+1;
z=z*z+z0;
end
count=log(count);Shan Yinhttps://jp.mathworks.com/matlabcentral/profile/authors/14145224-shan-yintag:jp.mathworks.com,2005:Question/4358782018-12-15T11:16:43Z2018-12-15T11:16:43Zdetecting spikes am working on LIF (leaky integrated fire neuron) and i give periodic ramp signal as excitation current. now i want how to detect how many spikes occur inside each ramp windows. so if you have any idea about it someone give me hint...am working on LIF (leaky integrated fire neuron) and i give periodic ramp signal as excitation current. now i want how to detect how many spikes occur inside each ramp windows. ASHENAFI FEKEDE HAILEhttps://jp.mathworks.com/matlabcentral/profile/authors/13312698-ashenafi-fekede-hailetag:jp.mathworks.com,2005:Question/4358762018-12-15T11:08:09Z2018-12-15T11:13:26ZI am writing an FEM code for a curved box girder bridge and getting an error..Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 9.359430e-32. > In Dec14 (line 579) X_matrix=inv(K_modi)*F_matrix;Virajan Vermahttps://jp.mathworks.com/matlabcentral/profile/authors/13253143-virajan-vermatag:jp.mathworks.com,2005:Question/3951442018-04-16T05:03:16Z2018-12-15T11:01:01Zi am trying to solve bouc-wen hysteresis model anybody help me to solve this problemi am trying to solve the bouc-wen hysteresis model using ordinary differential equations help me solve this problemSABARIANAND D Vhttps://jp.mathworks.com/matlabcentral/profile/authors/8832171-sabarianand-d-vtag:jp.mathworks.com,2005:Question/4358742018-12-15T10:51:45Z2018-12-15T10:51:45ZGet position and dimensions of rectangular ROI as normalised [0,1] instead of pixelsI can use h = drawrectangle() and then get the position and dimensions using h.Position. This gives me an answer in pixels but I would like them as normalised to the image, between 0 and 1. Is there a way to do this in MATLAB without calculating it from the height and width of the image? It's fairly trivial to do this manually, I just wondered if there may be a function that would do it for me.KiFi85https://jp.mathworks.com/matlabcentral/profile/authors/13856860-kifi85tag:jp.mathworks.com,2005:Question/4358732018-12-15T10:46:42Z2018-12-15T10:46:42ZNumerically solve integration of random variable using symbolic valuesHello,
I am trying to solve an equation in matlab using symbolic values and a random variable with a lognormal distribution. This is the code I have so far:
FOCR=0.0036;
sigma=1;
syms eB
func= @(X) X.*pdf('Lognormal',X,0,sigma);
N=int(func,X,eB,inf);
D=exp(0.5*sigma^2)-N;
EB=solve(N/D==FOCR,eB);
When I execute this code step by step I notice that I get an error when I try to compute the integral, N of func on [eB,inf]. This is what the error says:
Error using symengine
Unable to prove 'X <= 0' literally. Use 'isAlways' to
test the statement mathematically.
Error in sym/subsindex (line 821)
X =
find(mupadmex('symobj::logical',A.s,9))
- 1;
Error in sym/privsubsasgn (line 1096)
L_tilde2 =
builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 933)
C = privsubsasgn(L,R,inds{:});
Error in lognpdf (line 36)
x(x <= 0) = Inf;
Error in pdf (line 107)
y = lognpdf(x,a,b);
Error in @(X)X.*pdf('Lognormal',X,0,sigma)
Error in sym>funchandle2ref (line 1302)
S = x(S{:});
Error in sym>tomupad (line 1215)
x = funchandle2ref(x);
Error in sym (line 214)
S.s = tomupad(x);
Error in sym/int (line 63)
f = sym(f);
Does anyone know how to solve this issue or what I am doing wrong here?
Thanks in advance,
RenéRené Wijnenhttps://jp.mathworks.com/matlabcentral/profile/authors/14054194-rene-wijnentag:jp.mathworks.com,2005:Question/4358722018-12-15T10:32:40Z2018-12-15T10:32:40ZElectric Load Time-Series Forecasting using AR, KNN and SVMI want to forecast the next week (horizon = 7) electric load with lag=7 using AR, KNN and SVM, where should I start? Is there a code that could help me with that or even a tutorial ?Mohab Mostafahttps://jp.mathworks.com/matlabcentral/profile/authors/6462704-mohab-mostafatag:jp.mathworks.com,2005:Question/4334622018-12-03T07:17:22Z2018-12-15T10:18:42ZHow to find five unknown parameters of an equationHello all,
Greetings.
I am very new to matlab.
How to find five unknown parameters of an equation. Looking for help on this.
My Equation,
Y = [a * B^c * D^-0.33 * exp(-e / FG)] – [h * J]
Where, [ G = k * L + m * N ] ;
Here unknown parameters are [ a, c, e, k, h ]
Known parameters are [ B, D, F, J, L, N]
these parameters have constraints like, (0<k>1); (m = 1 - k); (a>0); (c<0); (e>0); (h>0) and (Y>0)
I have to draw X-Y plot graph and also Least square regression analysis.
I have X-axis values, Y-axis values will be calculated from equation Y.
X = [0.0000032; 0.0000201; 0.00000280; 0.0000114; 0.00000790; 0.00000560; 0.000004; 0.0000012]
B = [53855; 27506; 52678; 27002; 26654; 27013; 53949; 53091]
D = [8.39; 8.32; 8.52; 8.42; 8.50; 8.61; 8.50; 8.60]
F = [0.0083; 0.0083; 0.0083; 0.0083; 0.0083; 0.0083; 0.0083; 0.0083]
L = [687; 740; 670; 705; 674; 647; 677; 649]
N = [636; 644; 624; 633; 626; 617; 626; 618]
J = [12; 4; 12; 3; 4, 3; 12; 13]
I have to find the unknown parameters using “Y” equation and later plot X-Y parity plot it should have R^2 > 0.85
Appreciate your help.
Thanks in advance.HARISH GANAPATHIhttps://jp.mathworks.com/matlabcentral/profile/authors/11803641-harish-ganapathitag:jp.mathworks.com,2005:Question/4358712018-12-15T10:12:03Z2018-12-15T10:12:03ZHow can i solve network verification error when installing support package for matlab2016a Saad Shahhttps://jp.mathworks.com/matlabcentral/profile/authors/14340762-saad-shahtag:jp.mathworks.com,2005:Question/1676652014-12-22T11:25:51Z2018-12-15T10:05:04ZCan any one help me how to write a matlab code for UPFC and IPFC modelling of a network with newton-raphson methodSir,
I am working on a project based on IPFC but we are get struck in writing or getting a matlab code for this so, I request any one can give a code please at-least for upfc please help us for moving my work forward pleaseravihttps://jp.mathworks.com/matlabcentral/profile/authors/6006941-ravitag:jp.mathworks.com,2005:Question/4357882018-12-14T15:53:22Z2018-12-15T09:57:47ZExtract part of image using maskHello,
For a project I need to extract only a part of my image. I already have a mask of that image (same size) and would like to extract the part of the image that is coloured white in the mask. See images in attachment.
Thank you in advance
Miel AchtenMiel Achtenhttps://jp.mathworks.com/matlabcentral/profile/authors/14298357-miel-achtentag:jp.mathworks.com,2005:Question/4356322018-12-13T19:44:48Z2018-12-15T09:53:22ZProblems with plotting multiple objects
Hi! I have a question. There are the label of contour on the rectangle. Can I delete this for a better reading? Thank you
This is the code for the graphic part.
[c,cc]=contour(x,y,u',[13.1,13.5,14,14.5,15,15.5,15.9]);
clabel(c,cc,'LabelSpacing',72,'Color','r','FontWeight','normal');
rectangle('position',[0,0,Lx,Ly])
rectangle('position',[x(6),y(4),d,3*d],'FaceColor',[0.5 0.5 0.5],'LineWidth',1)
axis('equal');
set(cc,'ShowText','on');
colormap cool;
axis([0 Lx 0 Ly]);
hold on;
streamline(x,y,qx,qy,[x(2:4),x(9:nx)], y(ny+1)*ones(1,6));
quiver(x(2:5),y(2:ny),qx(2:ny,2:5),qy(2:ny,2:5),'b');
quiver(x(8:nx),y(2:ny),qx(2:ny,8:nx),qy(2:ny,8:nx),'b');
quiver(x(6:7),y(2:3),qx(2:3,6:7),qy(2:3,6:7),'b');
trimesh(T,P(:,1),P(:,2),hh);
title('Sheet pile wall');
xlabel('x');ylabel('y');zlabel('z');MICHELA VOLGAREhttps://jp.mathworks.com/matlabcentral/profile/authors/13760896-michela-volgaretag:jp.mathworks.com,2005:Question/4358692018-12-15T08:43:33Z2018-12-15T09:51:57ZI have a set of second order differential nonlinear equation and I want to solve them together with ode45, how could I write codes for them?or better to say I want to define state transition function for such equations.first three equations all variable and constants are not in vector or matrix form but 4th equation is a 3by1 vector like this:
x''=y'+y+x-(x)/(x^2+y^2+z^2)^1.5+1
y''=x'-x+y-y/(x^2+y^2+z^2)^1.5
z''=-z/(x^2+y^2+z^2)^1.5
m''=[x'' y'' z'']'+[1 2 3]
and I want to write function for this system like this function that i have found in one of matlab example:
function dxdt = vdpStateFcnContinuous(x)
%vdpStateFcnContinuous Evaluate the van der Pol ODEs for mu = 1
dxdt = [x(2); (1-x(1)^2)*x(2)-x(1)];
endroya afsharhttps://jp.mathworks.com/matlabcentral/profile/authors/12973550-roya-afshartag:jp.mathworks.com,2005:Question/4358532018-12-15T00:46:43Z2018-12-15T09:46:00ZHow can I evaluate the double integral of a piece-wise function and get a numerical answer, instead of the rewritten integral?pieclc;
clear;
R0plus = input('Entera value for R0+');%%Might have to change to syms%%%
syms yplus;
rplus = R0plus-yplus;
kappa=0.4;
yplusn=11;
%%if statements%%%%Reichardt (1951)%%
%syms Eoverv
Eoverv = piecewise(yplus<=50, 0.4*(yplus-(11*tanh(yplus/11))), yplus>50,(0.4/3)*yplus.*(0.5+(((R0plus-yplus)/R0plus)^2)).*(1+((R0plus-yplus)/R0plus)) );
up= (R0plus-yplus)./(Eoverv-1);
q= int(up,yplus, [0 yplus]);
uplus=(q./R0plus);
um = uplus.*(R0plus-yplus);
syms umplus;
umplus=int(um,yplus,0,R0plus)
subs(umplus)
The result is int(-(int((yplus - 10)/((22*tanh(yplus/11))/5 - (2*yplus)/5 + 1), yplus, 0, yplus)*(yplus - 10))/10, yplus, 0, 10).
I need the result of the integral not the problem rewritten. I should be given a numerical answer.Armando Gamezhttps://jp.mathworks.com/matlabcentral/profile/authors/14165222-armando-gameztag:jp.mathworks.com,2005:Question/3629912017-10-24T15:29:59Z2018-12-15T09:38:45ZHow can I use plotm from the mapping toolbox in AppDesignerLooking to include Map data how can I include a plotm in a AppDesigner app?Scotthttps://jp.mathworks.com/matlabcentral/profile/authors/1178717-scotttag:jp.mathworks.com,2005:Question/4358702018-12-15T09:35:25Z2018-12-15T09:35:25ZSending data larger than 1 byte from Arduino to Simulink via Serial CommunicationI want to send simply numbers from Arduino to MATLAB via serial communication. I am perfectly sending values in between 0-255 however I also want to send larger values. Probably, Simulink reads it byte by byte however I couldn't figure how to combine those bytes to get a meaningful data.
Below, you may see my Arduino code and simulink block diagram.
My question can be simplified as this; "How can I send the double value 500 to MATLAB Simulink from Arduino?" I want to take that number 500 as a number to use control applications for example.
Thanks.
Sinan Sahin Candanhttps://jp.mathworks.com/matlabcentral/profile/authors/4659008-sinan-sahin-candantag:jp.mathworks.com,2005:Question/1128742014-01-19T08:25:11Z2018-12-15T09:29:04Zhow to divide image into 3x3 blocks? '9 parts'i have one rgb image, i converted it to gray then to binary, did imfill, further i want to split that image into 9 blocks i.e 3x3 , please help menitesh patilhttps://jp.mathworks.com/matlabcentral/profile/authors/4958551-nitesh-patiltag:jp.mathworks.com,2005:Question/4354472018-12-12T21:51:19Z2018-12-15T09:28:22Zhow can i write this code i a better form Ashrakat Adelhttps://jp.mathworks.com/matlabcentral/profile/authors/13780134-ashrakat-adeltag:jp.mathworks.com,2005:Question/4356032018-12-13T17:46:26Z2018-12-15T09:25:46ZI'm trying to make a Simpsons Rule Function MyselfI've had a few attempts at this question and have developed my answer further each time. If people wouldn't mind giving feedback or correcting my code that'd be great.
This is the question:
and the code I have written to answer this is, there is more to th question but this is just my code for the first bit:
function [y] =MPR_Asgn4_Q4a_26024405(f,a,b,n)
h=(b-a)/n;
x=zeros(1,n+1);
x(1)=a;
x(n+1)=b;
s1=0;
s2=0;
s3=0;
for k = 2:n
x(k)=a+h*(1i-1);
end
for k=1:n/2
s1= s1 + f(x(2*1i-1));
end
for k=1:n/2
s2=s2+f(x(2*1i));
end
for k= 1:n/2
s3 = s3 +f(x(2*1i+1));
end
y = (h/3)*(s1+(4*s2)+s3);
disp(y);
endJack Bushhttps://jp.mathworks.com/matlabcentral/profile/authors/13883834-jack-bushtag:jp.mathworks.com,2005:Question/3515252017-08-04T07:07:35Z2018-12-15T09:10:02ZColor-Based Segmentation Using K-Means Clustering Hi i found this tutorial about segmenting colors from images in
http://www.mathworks.com/help/images/examples/color-based-segmentation-using-k-means-clustering.html
There is a part there wherein the colors has been segmented into 3 part
for k = 1:nColors
color = he;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
Now the output is partitioned into 3 separate colors
IE.
image 1 contains only blue
image 2 contains only yellow
image 3 contains only brown
now what i am asking is how can i just get the brown partition? In my example the position of the brown color is 3 but sometimes when i partition other images, The position of the brown color becomes 2. How can i determine what color goes to which partition when using the LAB colorbased segmentation?
Thanks in advance :)Albert Rey Ruelanhttps://jp.mathworks.com/matlabcentral/profile/authors/9058550-albert-rey-ruelantag:jp.mathworks.com,2005:Question/927012010-11-05T13:43:00Z2018-12-15T09:03:19ZHow do I pass out extra parameters using ODE23 or ODE45 from the MATLAB ODE suite?I would like to return some parameters from the ode45 solution that do not need to be integrated, but which are important to the result. I would like to have the function I pass to ODE23/ODE45 return extra parameters which the ODE solver ignores during the computation but stores for later review.
MathWorks Support Teamhttps://jp.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:jp.mathworks.com,2005:Question/4356962018-12-14T07:37:19Z2018-12-15T09:01:59ZHow can I detect that which squares are ticked in the image?How can I detect that which squares are ticked in the image?
I'm think use the normxcorr2 or imshowpair to compare the original image with ticked image, but I not sure how to do this.
Original Image:
AlexMThttps://jp.mathworks.com/matlabcentral/profile/authors/8178244-alexmttag:jp.mathworks.com,2005:Question/4357192018-12-14T09:42:01Z2018-12-15T08:55:47ZHow to save alphashape image as STL or CAD?How to save alphashape image as STL or CAD? can any share idea's?Selva Karnahttps://jp.mathworks.com/matlabcentral/profile/authors/4733665-selva-karnatag:jp.mathworks.com,2005:Question/4358402018-12-14T21:07:42Z2018-12-15T08:54:43ZHow to continue without solution min max constraint problem.Hello,
Solving a min max constraint problem in matlab,is a part/function of my whole code. This function finds the optimal linear combination of the distributions, x and y such that it approximates z very good. The problem is that the code is terminated if the optimization problem cannot be solved. In that case I would like to use choose my own values for the optimal parameters.
So I wrote this part in the code:
%If the optimal solution is not found then:
if sum(OptArgum(1:2))<1
OptArgum(1)=0.5;
OptArgum(2)=0.5;
end
But It does not work. So now I am left with two questions:
1) Can you give me some suggestion for better code?
2) How can I add arguments to the code such as 'MaxFunEvals', 1000, 'Maxiter', 1000, such that the code is not terminated easily?
Thank you in advance
This is the code of my function:
function[OptArgum,v]=ModelParametersMinMax (x, y, z)
%This function finds the optimal linear combination of the distributions, x and y such that it approximates z very good. z=a*x+(1-a)*y
%input
% x =The pdf vector of process x
% y =The pdf vector of process y
% z =The pdf vector of all processes together
%output
%OptArgum=A vector that consist of three entrees all coefficients for x,y and z
%v =A linear combination of the x and y such that v can be approximated by: a*x+(1-a)*y
%Construction of the constraint matrix
Aleq=[];
bleq=[];
Aeq=[1 1 0];
beq=1;
%bound of the variables
lb=[0 0 0];
ub=[];
x0=0.1*rand(3,1);%initial guess
Cs=[x y -z];%coefficients of the objective function
% Solving the minmax constraint problem
[OptArgum, ~] = fminimax(@(x) Cs*x,x0,Aleq,bleq(:),Aeq,beq,lb,ub);
%If the optimal solution is not found then:
if sum(OptArgum(1:2))<1
OptArgum(1)=0.5;
OptArgum(2)=0.5;
end
v=OptArgum(1)*xPred + OptArgum(2)*xEstimatedRate;%approximation for z
end
Clarisha Nijmanhttps://jp.mathworks.com/matlabcentral/profile/authors/9730139-clarisha-nijmantag:jp.mathworks.com,2005:Question/4358672018-12-15T08:14:52Z2018-12-15T08:54:34ZHow to (efficiently) replace eval() with subs() for symbolic equationsHi,
I've been trying to convert a code I have for modeling a curve into a Simulink model (so, eventually, I'll be able to run automatic parameter estimation). The code itself is comprised of a few different symbolic functions. I previously used the code in Matlab 2012b (where it exectutes very quickly without problems) however I couldn't make it work in Simulink because of the C++ compiler issue. I tried to apply the patches to resolve the compiler problem with no sucess so I gave up and switced over to 2018b. Now the problem seems to be trying to replace the eval() function which is no longer supported. My best solution to date uses sub() and str2sym(). This works but is so slow that it's effectively useless. Does anybody have suggestions on how I can improve the code?
Old version:
for kt=1:nnt
tt=radt(kt); s=alfa/tt; bt=beta/tt; btF=bt.*eval(FF); ft(kt)=sum(real(btF));
end
New version:
btf=@(s,bt) double(bt.*subs(str2sym(Fs)));
for kt=1:nnt
tt=radt(kt); s=alfa/tt; bt=beta/tt; btF=btf(s,bt); ft(kt)=sum(real(btF));
end
For reference, a simplified version of FF is: '(0.1*s)^(1/2)*besselk(0.0, 8.0*(0.1*s)^(1/2))'
I'll include the files being used in case anyone would like to take a look in more detail.
Thanks in advance for any assistance!Nat Ahttps://jp.mathworks.com/matlabcentral/profile/authors/13679374-nat-atag:jp.mathworks.com,2005:Question/4357632018-10-24T04:00:00Z2018-12-15T08:50:09ZWhy does mex sometimes change its supported compilers from release to release?Are there any technical reasons behind the change from supported compilers? For example, from releases R2017b to R2018a, the supported compiler changed from gcc 4.9 to gcc 6.3 for Linux platforms. Can we still use gcc 4.9 in releases R2018a or newer?
MathWorks Support Teamhttps://jp.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:jp.mathworks.com,2005:Question/4358452018-12-14T22:14:05Z2018-12-15T08:47:04ZHow can I use pushbuttons in GUI to categorize a "like" or "dislike" of a imageI've been stuck on this problem and can't seem to find the right kind of tutorials online that would point me in the right direction.
My goal is to use a GUI that has two pushbuttons, a "like" and a "dislike" pushbutton.
I add the folder with all the images to my path so when my gui opens, the first image automatically pops up. Then I hit "like" or "dislike", and that information is saved as a logical corresponding to the image title in a structural array.
I've spent several hours working on creating practice GUI's that do other things to understand how everything works together, but I'm feeling in over my head maybe? Does anyone have any idea's, hints, or resources that they have in mind? Rachel Larsenhttps://jp.mathworks.com/matlabcentral/profile/authors/13575761-rachel-larsentag:jp.mathworks.com,2005:Question/4358632018-12-15T05:01:15Z2018-12-15T08:26:49ZHi, I tried to use fmincon but I received the message. How should I doNo feasible solution found.
fmincon stopped because it is unable to find a point locally that satisfies
the constraints within the selected value of the constraint tolerance."
The information of iter-detailed is as followings:
Max Line search Directional First-order
Iter F-count f(x) constraint steplength derivative optimality Procedure
0 82 -1.0034 3480 Infeasible start point
1 164 -1.00515 354.8 1 -0.0335 0.0813
2 246 -1.00601 3.686 1 -0.143 0.0103 Hessian modified
3 328 -1.00605 0.4859 1 -0.00621 0.028 Hessian modified twice
4 410 -1.00609 4.929 1 -0.00223 0.0104 Hessian modified
5 492 -1.00607 0.04732 1 0.00508 0.0124 Hessian modified
6 574 -1.00609 0.9597 1 -0.00141 0.00355 Hessian modified
7 656 -1.00609 0.1974 1 0.000492 0.00839 Hessian modified
8 738 -1.00609 0.1946 1 -0.000677 0.00758 Hessian modified
9 820 -1.0061 0.4714 1 -0.000696 0.0079 Hessian modified
10 902 -1.00611 0.6442 1 -0.000577 0.00731 Hessian modified
11 984 -1.00611 0.4668 1 -0.000491 0.00573 Hessian modified
12 1066 -1.00611 0.1859 1 -0.000216 0.00408 Hessian modified
13 1148 -1.00612 0.09291 1 -0.000407 0.00281 Hessian modified
14 1230 -1.00612 0.1776 1 -0.000519 0.00229 Hessian modified
15 1312 -1.00612 0.1746 1 -0.000331 0.00216 Hessian modified
16 1394 -1.00612 0.1142 1 -0.000213 0.00194 Hessian modified
17 1476 -1.00612 0.05896 1 -0.000156 0.00157 Hessian modified
18 1558 -1.00612 0.03069 1 -0.000157 0.00114 Hessian modified
19 1640 -1.00612 0.02441 1 -0.000176 0.000808 Hessian modified
20 1722 -1.00612 0.01698 1 -0.000115 0.000603 Hessian modified
21 1804 -1.00612 0.0127 1 -0.000126 0.000493 Hessian modified
22 1886 -1.00613 0.022 1 -0.00015 0.000418 Hessian modified
23 1968 -1.00613 0.03507 1 -0.000132 0.000473 Hessian modified
24 2050 -1.00613 0.03321 1 -9.43e-05 0.000506 Hessian modified
25 2132 -1.00613 0.01247 1 -2.54e-05 0.000477 Hessian modified
26 2214 -1.00613 0.003293 1 -2.49e-05 0.000418 Hessian modified
27 2296 -1.00613 0.00362 1 -9.51e-05 0.000384 Hessian modified
28 2378 -1.00613 0.007073 1 -8.52e-05 0.000384 Hessian modified
29 2460 -1.00613 0.009218 1 -5.33e-05 0.000338 Hessian modified
30 2542 -1.00613 0.004685 1 -1.87e-05 0.000265 Hessian modified
31 2624 -1.00613 0.001295 1 -1.44e-05 0.00022 Hessian modified
32 2706 -1.00613 0.001563 1 -4.72e-05 0.000174 Hessian modified
33 2788 -1.00613 0.003719 1 -4.91e-05 0.000173 Hessian modified
34 2870 -1.00613 0.006714 1 -4.17e-05 0.000221 Hessian modified
35 2952 -1.00613 0.005654 1 -2.72e-05 0.000206 Hessian modified
36 3034 -1.00613 0.001384 1 5.8e-06 0.000195 Hessian modified
37 3116 -1.00613 0.0002221 1 8.04e-06 0.00019 Hessian modified
38 3205 -1.00613 0.0005137 0.00781 -1.65e-05 0.0028 Hessian modified twice
39 3287 -1.00613 5.943e-05 1 -2.05e-05 0.000168 Hessian modified twice
40 3373 -1.00613 0.003659 0.0625 -4.37e-05 0.0245 Hessian modified twice
41 3455 -1.00613 0.002154 1 -2.31e-06 0.00426 Hessian modified
42 3537 -1.00613 0.0005249 1 1.52e-05 0.00173 Hessian modified
43 3619 -1.00613 4.381e-05 1 1.2e-06 0.00274 Hessian modified twice
44 3702 -1.00613 0.0009695 0.5 -1.1e-05 0.00417 Hessian modified twice
45 3784 -1.00613 0.0003152 1 -2.98e-06 0.0014 Hessian modified twice
46 3868 -1.00613 0.0005202 0.25 -8.04e-06 0.00419 Hessian modified twice
47 3950 -1.00613 7.217e-05 1 3.38e-07 0.00181 Hessian modified twice
48 4034 -1.00613 0.001222 0.25 -2.22e-05 0.0114 Hessian modified twice
49 4116 -1.00613 0.0001325 1 3.9e-06 0.00276 Hessian modified twice
50 4201 -1.00613 0.0003558 0.125 -9.74e-06 0.011 Hessian modified twice
51 4284 -1.00613 0.0003304 0.5 -2.31e-06 0.00369 Hessian modified twice
52 4370 -1.00613 0.000355 0.0625 -1.73e-06 0.00504 Hessian modified twice
53 4453 -1.00613 0.0003366 0.5 -2.58e-06 0.00199 Hessian modified twice
54 4535 -1.00613 0.0001426 1 -7e-07 0.00524 Hessian modified twice
55 4621 -1.00613 0.0001588 0.0625 -1.36e-06 0.00287 Hessian modified twice
56 4703 -1.00613 0.0002567 1 -7.95e-06 0.00522 Hessian modified twice
57 4788 -1.00613 0.0003902 0.125 -4.47e-06 0.00765 Hessian modified twice
58 4870 -1.00613 0.0001447 1 1.06e-08 0.00525 Hessian modified twice
59 4953 -1.00613 0.0001969 0.5 -2.09e-06 0.00483 Hessian modified twice
60 5052 -1.00613 0.0001969 7.63e-06 -2.24e-06 4.83 Hessian modified twice yuwan duanhttps://jp.mathworks.com/matlabcentral/profile/authors/14370518-yuwan-duantag:jp.mathworks.com,2005:Question/4358682018-12-15T08:19:47Z2018-12-15T08:19:47ZHow do I connect my USB microphone to the Audio Writer block in Simulink?Hi guys, I have a simple Simulink model shown in the picture. I have connected a USB micophone to my laptop. However I cant find the Device when I double click the 'Audio Writer' block in Simulink. What should I do to read the Audio from my USB microphone inside Simulink? Thank you.Aidil Adamhttps://jp.mathworks.com/matlabcentral/profile/authors/11836183-aidil-adamtag:jp.mathworks.com,2005:Question/4358652018-12-15T07:29:16Z2018-12-15T07:29:16ZHow I can plot a vehicle's velocity at different points on a mapI am working on driverless car. I have rosbag data. Now I have to plot imu and Gps data on a given map. How can I do that. Such that at every point on map I have knowledge of at what point what was yaw angle, what was velocity, acceleration etc.Ichchhit Kumarhttps://jp.mathworks.com/matlabcentral/profile/authors/13917399-ichchhit-kumartag:jp.mathworks.com,2005:Question/2703032016-02-27T10:31:44Z2018-12-15T06:55:34Zfind distance of points to centre of object?hi,
how can find the distance of a,b and c to the centre of object (red point) in a binary image. I've found the the centre, but finding distances of a,b,c looks difficult to me. thank you.
<</matlabcentral/answers/uploaded_files/46265/3.jpg>>
Abohttps://jp.mathworks.com/matlabcentral/profile/authors/5840315-abotag:jp.mathworks.com,2005:Question/4351032018-12-11T07:52:42Z2018-12-15T06:51:40ZIs there a GPU progress monitor?I have been looking for GPU progress monitor, similar to ones for CPU, e.g. like this one.
How come thre is not monitor for GPU calculation yet? Can it be expected in the future?
rokPhttps://jp.mathworks.com/matlabcentral/profile/authors/6476850-rokptag:jp.mathworks.com,2005:Question/4265212018-10-28T06:45:41Z2018-12-15T06:20:18ZWhile rotating the object in Simscape Multibody 3D simulation the object suddenly gets disappeared from the view. How to fix this issue ? when I do not rotate the object in 3D animation, the body remain in there.
I tried to use 'fit to view' in 3D animation, the object comes there for a fraction of a second and again gets disappeared from the view.Somesh Jaipuriahttps://jp.mathworks.com/matlabcentral/profile/authors/13285500-somesh-jaipuriatag:jp.mathworks.com,2005:Question/4357692018-12-14T14:17:42Z2018-12-15T06:18:59ZRead data from Excel and turn from cell into a text strHi guys! I'm trying to read data from excel usign the script below.
[~,txt,raw] = xlsread('config_SCADA.xls');
.
.
.
if available_Dev == 1
start_ln=33; % data block start line
end_ln=start_ln;
for i=end_ln:length(raw(:,1));
if raw{i,1} == 1 && isnan(raw{i,1})~=1 && isempty(raw{i,1})~=1;
NameX(i,1) =(txt(i,3));
IDX(i,1)=(raw{i,4});
else
Name_Dev = {};
ID_Dev= [ ];
end
end
Name_Dev = NameX(end_ln:end);
ID_Dev = IDX(end_ln:end);
empties = find(cellfun(@isempty,Name_Dev));
Name_Dev(empties) = []; % Here I want to delete the empty cells
Name_Devss =(Name_Dev).' % Wanna transpose the data from vertical to horizontal (from a column to a row)
Name_D = Name_Devss;
class(Name_D)
And the results look like :
Name_D =
Columns 1 through 8
'XT_Ubat' 'XT_Ibat' 'XT_Ubat_min' 'XT_I_in' 'XT_P_out' 'XT_F_out' 'XT_F_in' 'XT_P_in_a'
Columns 9 through 11
'XT_P_out_a' 'XT_T_elec1' 'XT_Ubat_ond'
ans =
cell
% Now because of the not appropriate type of the data ( cell ) I want
% to convert Name_D to a text ( string, char )
...
Name_Devss =char(Name_Dev).' % Wanna transpose the data from vertical to horizontal (from a column to a row)
Name_D = Name_Devss;
class(Name_D)
%_____________________ Now you can see the results __________________________________
Name_D =
XXXXXXXXXXX
TTTTTTTTTTT
___________
UIUIPFFPPTU
bbb_______b
aaaiooiioea
tttnuunnult
_ tt _te_
m a_co
i a1n
n d
% It turns array letter by letter, All I want is to have the data in text frotmat horizontally
Help Please!
John Rebbnerhttps://jp.mathworks.com/matlabcentral/profile/authors/13894292-john-rebbnertag:jp.mathworks.com,2005:Question/1970462015-04-10T04:14:54Z2018-12-15T06:10:28ZInterpolating Frames of the VideoI have two videos of 1 min each. First video has 900 frames whereas second video has 600 frames. So I am trying to interpolate second video to have 900 frames. Can anyone tell me how this can be done?rohan guptahttps://jp.mathworks.com/matlabcentral/profile/authors/5546954-rohan-guptatag:jp.mathworks.com,2005:Question/454502012-08-07T10:44:32Z2018-12-15T06:08:26ZMissing data values with interpolationHello everybody,
I have a cell array each containing a sequence of diferent values. The sequences contains some missing values (I've represented with NaN). I would like to replace all this NaN places with numbers. I think the better way is do an interpolation but I don't know how to code this Nan and how to save it on a table in Matlab.
I1= interp1(x,y,'linear');
Greetings,
Pd) I've tried this but it doesn't work
nanData = isnan(y);
index = 1:numel(y);
data2 = y;
data2(nanData) = interp1(index(~nanData), y(~nanData), index(nanData));
Emmanuellehttps://jp.mathworks.com/matlabcentral/profile/authors/3593649-emmanuelletag:jp.mathworks.com,2005:Question/4355372018-12-13T10:16:23Z2018-12-15T06:02:37ZHow to use a variant sink depending on its inputI have a s-function and it has 6 outputs, the next step is to check is there a negtive in 6 outputs. If there is one negtive, the simulation should be stop. If there is not, the 6 outputs should be passed to next s-function to continue simulating. In this case, I choose a variant sink, one of the output connects to stop block and another connects to next s-function to continue simulating. The thing is how can I use variant sink depending on its input rather than a pre-defined varable.
The pic shows how I use the variant sink, but it has an error saying that both the h and y (two of the outputs of s-funtion) are not defined.
Thank you very much！Bicheng Guohttps://jp.mathworks.com/matlabcentral/profile/authors/8061640-bicheng-guotag:jp.mathworks.com,2005:Question/4358642018-12-15T05:15:19Z2018-12-15T05:37:47Zi cannot get past license activationI am using a student licensed version of MATLAB. After downloading and setting up, it tells me to activate my license and i do it with a given from the website. On the website, it says the license is valid. After doing so, i cannot open matlab without having the license activation pop up and tells me to activate it again. I cannot seem to get past this. Please helpDavid Kimhttps://jp.mathworks.com/matlabcentral/profile/authors/4564416-david-kimtag:jp.mathworks.com,2005:Question/3799202018-01-31T05:10:40Z2018-12-15T05:35:26Zhow to find the height and width of an object <</matlabcentral/answers/uploaded_files/103022/A.jpg>>
I want to find the height and width of this image
I'd tried with this code but it does not give me the correct answer.
image1 = imread('C:\Program Files\MATLAB\R2016a\bin\WP_20180131_08_54_51_Selfie.jpg'); %Reads the image from location
I = rgb2gray(image1); % changes RGB input image into grayscale for edge detection
subplot(2,2,1);
image(image1); %Displays image
subplot(2,2,2);
image(I);
BW = edge(I); %detects edges in the grayscale image (only in gray scale)
[r1,c1] = find(BW);
subplot(2,2,3);
spy(BW);
x2 = max(r1);
x1 = min(r1);
X = x2 - x1
y2 = max(c1);
y1 = min(c1);
Y = y2 - y1
subplot(2,2,4);
imshow(BW);Rangika Markhttps://jp.mathworks.com/matlabcentral/profile/authors/9026710-rangika-mark