https://au.mathworks.com/matlabcentral/answers/questions MATLAB Answers — New Questions 2019-08-19T02:21:24Z tag:au.mathworks.com,2005:Question/472445 2019-07-19T05:32:14Z 2019-08-19T02:21:24Z Bisection help PLS HELP ME I have this code for a bisection method but I cant seem to figure out why it wont work I just get this error every thing else is given any help is appreciated thanks Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'. Error in bisectiona>f (line 65) x=(2*Fo/wn.^2-w.^2)*sin((wn-w/2)*t)*sin((wn+w/2)*t); Error in bisectiona (line 14) f_left = f(x_left); function bisectiona % Bisection method: Used for solving an equation, and finding an % approximate solution to an equation. clc % The number of bisection steps n = 32; % define the initial interval a = 41; b = 69; fprintf('\n initial interval [%g, %g] \n total bisection steps %d\n', a,b,n); % Check that a root does exist in the chosen interval x_left = a; x_right = b; f_left = f(x_left); f_right = f(x_right); if f_left*f_right > 0 end % Bisection: The method for i=1:n if f_left == 0 % The exact root of the equation is found at the lower bound % of the chosen interval fprintf('\n stage %g root %g with zero absolute error \n',i,x_left); return; end if f_right==0 % The exact root of the equation is found at the upper bound % of the chosen interval fprintf('\n stage %g root %g with zero absolute error \n',i,x_right); return end % Bisection method: The process x_mid = (x_left+x_right)/2.0; f_mid = f(x_mid); if f_left*f_mid <= 0 % There is a root in [x_left,x_mid] x_right = x_mid; f_right = f_mid; end if f_left*f_mid > 0 % There is a root in [x_mid,x_right] x_left = x_mid; f_left = f_mid; end % Calculate the approximate root for current step root = (x_left+x_right)/2.0; % Calculate the absolute error for current step abs_err=(x_right-x_left)/2.0; fprintf('\n stage %g root %g absolute error < %g \n',i,root,abs_err); end %check satisfaction of equation at end of process residual = f(root); fprintf('\n final residual = %g \n',residual); end %Created Subfunction to define equation f(x) function f_value = f(~) k = 2800; m = 0.6705; Fo = 2.0535; t = 9.177; x = 0.0253; w = 77:0.1:80; wn= sqrt(k/m); fo= Fo/m; x=(2*Fo/wn.^2-w.^2)*sin((wn-w/2)*t)*sin((wn+w/2)*t); f_value = x; end Triggs https://au.mathworks.com/matlabcentral/profile/authors/9080447-triggs tag:au.mathworks.com,2005:Question/472384 2019-07-18T16:06:46Z 2019-08-19T02:20:41Z MATLAB HELP ME PLS close all clear clc format long a=0; b=10; function [Distance] = trapezoidal(Speed, a, b, n) h = (b-a)/n; result = 0.5*Speed*a + 0.5*Speed*b; for i = 1:(n-1) result = result + Speed*(a + i*h); end [Distance] = h*result; fprintf('ans=%6.6ff\n',Distance) end Triggs https://au.mathworks.com/matlabcentral/profile/authors/9080447-triggs tag:au.mathworks.com,2005:Question/476262 2019-08-15T13:13:38Z 2019-08-19T02:16:08Z Preventing Emphasis in plot from Simulink Model I have a plot coming from a function used in a simulink model. When this plot is run every 10 ms it will bring the plot to the the foreground preventing me from doing other work while it is running. Is there any way to have this plot update in the background instead of in the foreground. I am using matlab/simulink 2015b and cannot use a newer version This is the function code function ProgressPlot(VehLatPos_m,VehLonPos_m,VirtVehLat,VirtVehLon,TrajInt,start_k,end_k,no_Vpp0) %plot one time step of vehicle motion in the course TrajDes.TrajCtr = TrajInt; px = (VehLonPos_m); py = (VehLatPos_m); virtx = (VirtVehLon); virty = (VirtVehLat); figure(25); %This is so it will replot over the previous figure, and not make a new one. if(no_Vpp0 == 1) plot(TrajDes.TrajCtr(1:end,1),TrajDes.TrajCtr(1:end,2),px,py,'+k'); else plot(TrajDes.TrajCtr(start_k:end_k,1),TrajDes.TrajCtr(start_k:end_k,2),'g',... TrajDes.TrajCtr(1:start_k-1,1),TrajDes.TrajCtr(1:start_k-1,2),'-r',... TrajDes.TrajCtr(end_k+1:end,1),TrajDes.TrajCtr(end_k+1:end,2),'-r',... px,py,'+k', virtx,virty,'ob'); end axis equal; title('Progress around Course') end William``` https://au.mathworks.com/matlabcentral/profile/authors/14635920-william tag:au.mathworks.com,2005:Question/476493 2019-08-17T06:43:13Z 2019-08-19T02:15:28Z how to drive this equations in simulink ? can anyone help me? Azaz Ali https://au.mathworks.com/matlabcentral/profile/authors/14750895-azaz-ali tag:au.mathworks.com,2005:Question/476626 2019-08-19T01:54:50Z 2019-08-19T02:09:09Z How do I preallocate my variables for speed when creating an SIR model? Hello. I am currently trying to graph an SIR model using matlab. I have a for loop in my code. My graph never seems to look right and I'm wondering if preallocating for speed might help. (Matlab also suggested this to me.) My code is as follows: for i=1:H % Update time t(i+1)=t(i)+h; % Update S, I & R k1S = fS(t(i) , S(i) , I(i) ); k1I = fI(t(i) , S(i) , I(i) ); k1R = fR(t(i) , I(i) ); k2S = fS(t(i)+h/2, S(i)+h/2*k1S, I(i)+h/2*k1I); k2I = fI(t(i)+h/2, S(i)+h/2*k1S, I(i)+h/2*k1I); k2R = fR(t(i)+h/2 , I(i)+h/2*k1I); k3S = fS(t(i)+h/2, S(i)+h/2*k2S, I(i)+h/2*k2I); k3I = fI(t(i)+h/2, S(i)+h/2*k2S, I(i)+h/2*k2I); k3R = fR(t(i)+h/2 , I(i)+h/2*k2I); k4S = fS(t(i)+h , S(i)+h *k3S, I(i)+h *k3I); k4I = fI(t(i)+h , S(i)+h *k3S, I(i)+h *k3I); k4R = fR(t(i)+h , I(i)+h *k3I); S(i+1) = S(i) + h/6*(k1S + 2*k2S + 2*k3S + k4S); I(i+1) = I(i) + h/6*(k1I + 2*k2I + 2*k3I + k4I); R(i+1) = R(i) + h/6*(k1R + 2*k2R + 2*k3R + k4R); end I could really use some help in figuring out how to get my model to work. Thanks. Anika Ang https://au.mathworks.com/matlabcentral/profile/authors/15938932-anika-ang tag:au.mathworks.com,2005:Question/476468 2019-08-16T21:44:14Z 2019-08-19T02:05:07Z How can I find a p-value when dealing with a weighted sum of chi-square distributions? I am working with a test statistic that is distributed as a weighted sum of chi-square distributions. Given a particular value x, how can I find its associated p-value? I believe I can use something like 1-chi2cdf(x,d) when dealing with just one chi-square distribution with d degrees of freedom. But what can I do if I have a weighted sum of chi-square distributions? Michael Orrison https://au.mathworks.com/matlabcentral/profile/authors/3745163-michael-orrison tag:au.mathworks.com,2005:Question/476624 2019-08-19T00:50:57Z 2019-08-19T02:02:16Z Changing default output in Publish (vsn 17b) How can I change the default output format in Publish? I am in an academic environment and want to publish to a .pdf (vs html). Versus do it everytime I log in, can I change the default output? Dawn Roberson https://au.mathworks.com/matlabcentral/profile/authors/586892-dawn-roberson tag:au.mathworks.com,2005:Question/476540 2019-08-17T21:24:32Z 2019-08-19T01:56:09Z How to get the values of for loop subsystem after every iteration in simulink Hi, I am using a for loop iterator in simulink. I am running the loop for 10 instances. I have a matlab function inside the for loop block which after every iteration would output a 1 by 4 vector. I am planning to use the 1 by 4 vector value after every iteration as an input to another block. The other block is present outside the for loop subsystem because placing it inside does not suit my necessity. How do i get the 1 by 4 vector value of each iteration value outisde the for loop subsystem? Right now, the for loop outputs only after completing all the 10 iterations. But, i need the output after every iteration. I have tried goto blocks and also tried writing it into the workspace and then using it again outside the subsystem, but none of the methods worked. Please let me know if there is any other way to do this. Thank you. Yokhesh KrishnasamyTamilselvam https://au.mathworks.com/matlabcentral/profile/authors/14607011-yokhesh-krishnasamytamilselvam tag:au.mathworks.com,2005:Question/476390 2019-08-16T11:39:13Z 2019-08-19T01:35:26Z How to close the boundary of a surface already generated by filling the holes from give matrix (attached), i am using following code to close the surface and to make a boundary but i am getting errors that indexing is out of bound. m = zeros(28) m = load('Matrix_Boundary_fills_3s_only.txt'); [rows, colms] = size(m); mOut = m; for row = 2 : rows % for colm = 1:colms if m(row-1, colm) == 3 mOut(row, colm+1) = 3; end if m(row-1, colm) == 3 || m(row-1,colm+2) == 3 mOut(row, colm+1) = 3; end if m(row-1, colm + 1) == 3 mOut(row, colm+1) = 3; end end end % end disp(mOut) thanks for all cooperation in advance. M.S. Khan https://au.mathworks.com/matlabcentral/profile/authors/13647580-m-s-khan tag:au.mathworks.com,2005:Question/475684 2019-08-10T19:01:41Z 2019-08-19T01:27:02Z Cpu usage in parrallel running mode Hi. I have code that running in parrallel mode. I have 4 worker(my cpu has 2 core) but when i run it, it shows that cpu fluctuate from 2 to 24 % but physical memory is in 96%(2×30% , 1×20,2×10%) ,anybody knows why cpu does not show more usage ;like 90%?thank you. ARMIN M https://au.mathworks.com/matlabcentral/profile/authors/15894092-armin-m tag:au.mathworks.com,2005:Question/476326 2019-08-15T22:49:49Z 2019-08-19T01:22:09Z Error using mex complier Unable to compile C++ code. I am using the following command to complie a .cpp file, but it throws an error. mex generateEllipseCandidates.cpp -IC:\opencv\build\include -IC:\opencv\build\include\opencv -IC:\opencv\build\include\opencv2 -IC:\opencv\build\x64\vc11\lib -Lopencv_core249 -Lopencv_highgui249 -Lopencv_imgproc249 -Llibmwlapack.lib -IC:\Users\jaimeetp\Documents\MATLAB\R2019a\extern\include -IC:\Users\jaimeetp\Documents\MATLAB\R2019a\extern\lib\win64\microsoft Error: mex generateEllipseCandidates.cpp -IC:\opencv\build\include -IC:\opencv\build\include\opencv -IC:\opencv\build\include\opencv2 -IC:\opencv\build\x64\vc11\lib -Lopencv_core249 -Lopencv_highgui249 -Lopencv_imgproc249 -Llibmwlapack.lib -IC:\Users\jaimeetp\Documents\MATLAB\R2019a\extern\include -IC:\Users\jaimeetp\Documents\MATLAB\R2019a\extern\lib\win64\microsoft Building with 'Microsoft Visual C++ 2019'. Error using mex Creating library generateEllipseCandidates.lib and object generateEllipseCandidates.exp generateEllipseCandidates.obj : error LNK2019: unresolved external symbol dggev referenced in function "int __cdecl fitEllipse2(double *,double *)" (?fitEllipse2@@YAHPEAN0@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::Exception::Exception(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (??0Exception@cv@@QEAA@HAEBV?\$basic_string@DU?\$char_traits@D@std@@V?\$allocator@D@2@@std@@00H@Z) referenced in function "void __cdecl cvCanny3(void const *,void *,void *,void *,int)" (?cvCanny3@@YAXPEBXPEAX11H@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl cv::Exception::~Exception(void)" (??1Exception@cv@@UEAA@XZ) referenced in function "void __cdecl cvCanny3(void const *,void *,void *,void *,int)" (?cvCanny3@@YAXPEBXPEAX11H@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "void __cdecl cv::error(class cv::Exception const &)" (?error@cv@@YAXAEBVException@1@@Z) referenced in function "void __cdecl cvCanny3(void const *,void *,void *,void *,int)" (?cvCanny3@@YAXPEBXPEAX11H@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPEAX@Z) referenced in function "public: __cdecl cv::Mat::~Mat(void)" (??1Mat@cv@@QEAA@XZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual class cv::Mat __cdecl cv::_InputArray::getMat(int)const " (?getMat@_InputArray@cv@@UEBA?AVMat@2@H@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl cv::_InputArray::getMatVector(class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > &)const " (?getMatVector@_InputArray@cv@@UEBAXAEAV?\$vector@VMat@cv@@V?\$allocator@VMat@cv@@@std@@@std@@@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual class cv::GlBuffer __cdecl cv::_InputArray::getGlBuffer(void)const " (?getGlBuffer@_InputArray@cv@@UEBA?AVGlBuffer@2@XZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual class cv::GlTexture __cdecl cv::_InputArray::getGlTexture(void)const " (?getGlTexture@_InputArray@cv@@UEBA?AVGlTexture@2@XZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual class cv::gpu::GpuMat __cdecl cv::_InputArray::getGpuMat(void)const " (?getGpuMat@_InputArray@cv@@UEBA?AVGpuMat@gpu@2@XZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl cv::_InputArray::kind(void)const " (?kind@_InputArray@cv@@UEBAHXZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual class cv::Size_<int> __cdecl cv::_InputArray::size(int)const " (?size@_InputArray@cv@@UEBA?AV?\$Size_@H@2@H@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual unsigned __int64 __cdecl cv::_InputArray::total(int)const " (?total@_InputArray@cv@@UEBA_KH@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl cv::_InputArray::type(int)const " (?type@_InputArray@cv@@UEBAHH@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl cv::_InputArray::depth(int)const " (?depth@_InputArray@cv@@UEBAHH@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl cv::_InputArray::channels(int)const " (?channels@_InputArray@cv@@UEBAHH@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl cv::_InputArray::empty(void)const " (?empty@_InputArray@cv@@UEBA_NXZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl cv::_OutputArray::fixedSize(void)const " (?fixedSize@_OutputArray@cv@@UEBA_NXZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl cv::_OutputArray::fixedType(void)const " (?fixedType@_OutputArray@cv@@UEBA_NXZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl cv::_OutputArray::needed(void)const " (?needed@_OutputArray@cv@@UEBA_NXZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual class cv::Mat & __cdecl cv::_OutputArray::getMatRef(int)const " (?getMatRef@_OutputArray@cv@@UEBAAEAVMat@2@H@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl cv::_OutputArray::create(class cv::Size_<int>,int,int,bool,int)const " (?create@_OutputArray@cv@@UEBAXV?\$Size_@H@2@HH_NH@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl cv::_OutputArray::create(int,int,int,int,bool,int)const " (?create@_OutputArray@cv@@UEBAXHHHH_NH@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl cv::_OutputArray::create(int,int const *,int,int,bool,int)const " (?create@_OutputArray@cv@@UEBAXHPEBHHH_NH@Z) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl cv::_OutputArray::release(void)const " (?release@_OutputArray@cv@@UEBAXXZ) generateEllipseCandidates.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl cv::_OutputArray::clear(void)const " (?clear@_OutputArray@cv@@UEBAXXZ) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "public: class cv::Mat & __cdecl cv::Mat::operator=(class cv::Scalar_<double> const &)" (??4Mat@cv@@QEAAAEAV01@AEBV?\$Scalar_@N@1@@Z) referenced in function "public: __cdecl cv::Mat_<float>::Mat_<float>(int,int,float const &)" (??0?\$Mat_@M@cv@@QEAA@HHAEBM@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "public: static class cv::MatExpr __cdecl cv::Mat::zeros(int,int,int)" (?zeros@Mat@cv@@SA?AVMatExpr@2@HHH@Z) referenced in function "void __cdecl calculateGradient3(double *,unsigned int,unsigned int,struct image_double_s * *)" (?calculateGradient3@@YAXPEANIIPEAPEAUimage_double_s@@@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "public: void __cdecl cv::Mat::create(int,int const *,int)" (?create@Mat@cv@@QEAAXHPEBHH@Z) referenced in function "public: __cdecl cv::Mat_<float>::Mat_<float>(int,int,float const &)" (??0?\$Mat_@M@cv@@QEAA@HHAEBM@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "public: void __cdecl cv::Mat::deallocate(void)" (?deallocate@Mat@cv@@QEAAXXZ) referenced in function "public: __cdecl cv::Mat::~Mat(void)" (??1Mat@cv@@QEAA@XZ) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "public: void __cdecl cv::Mat::copySize(class cv::Mat const &)" (?copySize@Mat@cv@@QEAAXAEBV12@@Z) referenced in function "public: __cdecl cv::Mat::Mat(class cv::Mat const &)" (??0Mat@cv@@QEAA@AEBV01@@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "void __cdecl cv::line(class cv::Mat &,class cv::Point_<int>,class cv::Point_<int>,class cv::Scalar_<double> const &,int,int,int)" (?line@cv@@YAXAEAVMat@1@V?\$Point_@H@1@1AEBV?\$Scalar_@N@1@HHH@Z) referenced in function mexFunction generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "void __cdecl cv::ellipse(class cv::Mat &,class cv::Point_<int>,class cv::Size_<int>,double,double,double,class cv::Scalar_<double> const &,int,int,int)" (?ellipse@cv@@YAXAEAVMat@1@V?\$Point_@H@1@V?\$Size_@H@1@NNNAEBV?\$Scalar_@N@1@HHH@Z) referenced in function mexFunction generateEllipseCandidates.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPEAHH@Z) referenced in function "public: __cdecl cv::Mat::Mat(class cv::Mat const &)" (??0Mat@cv@@QEAA@AEBV01@@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol cvGetMat referenced in function "void __cdecl cvCanny3(void const *,void *,void *,void *,int)" (?cvCanny3@@YAXPEBXPEAX11H@Z) generateEllipseCandidates.obj : error LNK2019: unresolved external symbol cvSobel referenced in function "void __cdecl cvCanny3(void const *,void *,void *,void *,int)" (?cvCanny3@@YAXPEBXPEAX11H@Z) generateEllipseCandidates.mexw64 : fatal error LNK1120: 36 unresolved externals Jaimeet Patel https://au.mathworks.com/matlabcentral/profile/authors/15364143-jaimeet-patel tag:au.mathworks.com,2005:Question/476602 2019-08-18T17:20:06Z 2019-08-19T01:00:46Z A for loop question for j=length(delta); for k=length(kinetic); if (delta(j)<=kinetic(k)) filling_degree_regionI(j,k)=1/(2*pi).*(pi*(abra)/180-((rh/R).*cosd(kappa-kinetic)./cosd(alpha).*sind(abra)./cosd(shai-kinetic))) filling_degree_regionI_new(1,k)=filling_degree_regionI(j,k); end end end for i=length(filling_degree_regionI_new); if filling_degree_regionI(i) > 0 new_filling_degree_regionI(i)=filling_degree_regionI(i); end end Thanks for your reply. I have [1*13] values of delta which are arranged [-90:30:270]. I use delta arrays to calculate kinetic[1*13]. Now I have to calculate filling degree using delta and kinetics. different filling depends on the values of delta and kinetic. it would be like that- filling_degree_regionI(1) will be calculated using delta(1) and kinetic(1). for filling_degree_regionI(2), delta(2) and kinetic(2) are needed. but there are two condition- 1) delta has to be less than equal to kinetics. I am confused how to make algorithms. Kashfia Mahin https://au.mathworks.com/matlabcentral/profile/authors/13150227-kashfia-mahin tag:au.mathworks.com,2005:Question/476431 2019-08-16T16:19:24Z 2019-08-19T00:44:09Z What's the best way to open and read a .out file in MATLAB? What's the best way to open and read a .out file in MATLAB? The file has numbers and text and I can open it as a plain text file in MATLAB, but how do I read the data in the file? I've tried fopen and textscan and had no success. Thank you! Maggie Fielder https://au.mathworks.com/matlabcentral/profile/authors/15784400-maggie-fielder tag:au.mathworks.com,2005:Question/353776 2017-08-23T13:03:12Z 2019-08-19T00:19:56Z smooth shading of patches in 3D - partially correct I am trying to render a nice 3d figure of a Voronoi cell by plotting the faces using the patch function and gouraud lighting to get smooth shading of the surfaces. The vertex normals are computed by a weighted average of the face (polygon) normals using the face areas as weights. It all looks relatively nice except that some faces do not have any light reflection. I cannot understand why I do not get the proper shading, and I would be very grateful any pointers to solve this. Here is how it looks with the associated vertex normals drawn <</matlabcentral/answers/uploaded_files/86202/vorCell.jpg>> and here is the code to produce it: fig = figure(); ax = axes('Parent',fig); p=patch('Faces',F,'Vertices',V); p.Parent = ax; hold(ax,'on'); p.FaceColor = [0.95 0.95 0.95]; p.VertexNormals = vnorm; for n = 1:nqV q=quiver3(V(n,1),V(n,2),V(n,3), vnorm(n,1), vnorm(n,2), vnorm(n,3) ); q.Color = [0.8 0.3 0.3]; q.LineWidth = 1.2; q.MaxHeadSize = 2; q.Parent = ax; q.AutoScale = 'off'; end view([-128 11]) axis equal lighting gouraud grid on with matrices F = [34 29 30 31 32 33 28 8 1 7 17 16 15 3 13 NaN NaN NaN NaN NaN 17 18 19 2 24 16 NaN NaN NaN NaN 13 17 18 5 11 NaN NaN NaN NaN NaN 7 1 19 18 5 NaN NaN NaN NaN NaN 16 24 25 14 15 NaN NaN NaN NaN NaN 25 24 2 22 NaN NaN NaN NaN NaN NaN 26 28 33 27 23 14 25 22 NaN NaN 31 30 6 21 NaN NaN NaN NaN NaN NaN 21 31 32 27 23 4 20 NaN NaN NaN 12 29 30 6 9 NaN NaN NaN NaN NaN 20 21 6 9 NaN NaN NaN NaN NaN NaN 33 27 32 NaN NaN NaN NaN NaN NaN NaN 22 26 8 1 19 2 NaN NaN NaN NaN 12 10 4 20 9 NaN NaN NaN NaN NaN 28 8 26 NaN NaN NaN NaN NaN NaN NaN 10 3 15 14 23 4 NaN NaN NaN NaN 34 11 5 7 NaN NaN NaN NaN NaN NaN 12 29 34 11 13 3 10 NaN NaN NaN]; V = [41.3411 42.6534 56.4570 42.9971 42.6986 56.0056 45.0957 42.6232 59.0728 43.0092 39.8638 59.3526 42.6463 44.4461 57.7151 42.1427 40.7134 60.4942 41.2465 44.0467 57.8011 41.5264 41.3264 56.3131 42.2348 40.7407 60.5345 44.1656 41.6457 60.0810 42.8749 44.4715 57.7761 42.5611 41.2097 60.7129 44.1996 44.2797 57.7430 44.5492 41.5642 57.9694 45.1375 42.5838 58.7361 44.6270 43.5925 57.2962 44.3424 44.0581 57.5101 43.1233 43.3174 56.4938 42.9432 42.7561 56.0245 42.8686 39.8425 59.4215 42.0284 39.7133 59.2071 42.9318 42.5213 56.0112 43.1946 39.8895 58.5593 44.5263 43.4475 57.1530 44.4736 41.7693 57.7335 41.6762 41.2894 56.2694 42.4125 39.7685 58.1382 41.5866 41.0063 56.4636 41.8281 41.6300 60.4530 41.9439 40.8349 60.4245 42.0070 39.7099 59.1804 41.9873 39.7061 58.9383 41.7631 40.2636 57.2521 41.4068 43.5440 58.8224]; vnorm = [-0.9742 0.0570 -0.2185 0.3383 0.0552 -0.9394 0.4967 0.4317 0.7529 0.6578 -0.6820 0.3196 -0.1656 0.8073 -0.5664 -0.2402 -0.6126 0.7530 -0.9892 0.1186 -0.0857 -0.9902 -0.1361 -0.0303 0.2504 -0.6009 0.7591 0.4696 0.2665 0.8417 0.0978 0.7705 0.6299 0.1726 0.5025 0.8472 0.2059 0.7654 0.6097 0.6904 -0.6060 -0.3951 0.9321 -0.3617 0.0181 0.8390 0.2851 -0.4635 0.4482 0.7058 -0.5487 -0.0528 0.6842 -0.7274 -0.1447 0.5425 -0.8275 0.2958 -0.7799 0.5516 0.0018 -0.9486 0.3166 0.4266 -0.4843 -0.7639 0.6181 -0.7014 -0.3551 0.7159 -0.0391 -0.6971 0.5699 -0.4910 -0.6589 0.3608 -0.5306 -0.7670 0.3938 -0.6983 -0.5977 -0.7569 -0.5513 -0.3510 -0.6932 0.3597 0.6245 -0.9805 -0.1564 0.1187 -0.9669 -0.2384 0.0911 -0.9626 -0.2614 0.0707 -0.7447 -0.5696 -0.3478 -0.6775 0.4064 0.6130]; Filip https://au.mathworks.com/matlabcentral/profile/authors/3421679-filip tag:au.mathworks.com,2005:Question/476513 2019-08-17T13:36:15Z 2019-08-18T23:56:59Z execution of my code in real time in "'gui" I created my fault detection code + I acquired in real time the image But I can not do the execution of my code in real time in "'gui" Aymen Mouelhi https://au.mathworks.com/matlabcentral/profile/authors/11705347-aymen-mouelhi tag:au.mathworks.com,2005:Question/476595 2019-08-18T15:44:50Z 2019-08-18T23:51:59Z How to run the same timer callback function multiple times in parallel I am working on a matlab code that uses guide to run a timer which in turn run for one time only. The timer callback function counts 10 numbers starting from the number provided in the text field in the guide. when I enter a number then press start putton it would start counting. I would like to know how to entera second number while the code is running and make matlab counts 10 numbers for both values (The first and the second) in parallel. let's say I entered 0 then I pressed the start button, then I immediately entered 10 and pressed the start button again. what happens now is that it counts only from 0 to 10. I would appreciate if you can share a way to make my code count from 0 to 10 and from 10 to 20 simultaneously in parrallel. start button function : function startbutton_Callback(hObject, eventdata, handles) t=timer; t.TimerFcn = @counter; t.Period = 15; t.ExecutionMode = 'fixedRate'; t.TasksToExecute = 1; start(t); stop (t); delete (t); Timer callback function: function counter(~,~) handles = guidata(counterFig); num = str2double(get(handles.edit1,'String')); for i = 0:10 disp (num); num = num+1; pause (1); end Ebrahim Atya https://au.mathworks.com/matlabcentral/profile/authors/14969891-ebrahim-atya tag:au.mathworks.com,2005:Question/369168 2017-11-25T11:11:14Z 2019-08-18T23:48:45Z When I try to find the mean rgb for the picture below, it give the value [230,160,168]. For my information, the value for red is [255,0,0]. Is it the background influence the value? <</matlabcentral/answers/uploaded_files/96066/1.jpg>> junnie vix https://au.mathworks.com/matlabcentral/profile/authors/9778375-junnie-vix tag:au.mathworks.com,2005:Question/476623 2019-08-18T23:06:23Z 2019-08-18T23:06:23Z implementation for tensor product equivalent to kron() function sara anwer https://au.mathworks.com/matlabcentral/profile/authors/12123545-sara-anwer tag:au.mathworks.com,2005:Question/476578 2019-08-18T12:02:03Z 2019-08-18T22:57:57Z Particle swarm optimisation problem Hello all, I am trying to use PSO for solving a system of nonlinear transcendental equations used in SHE PWM. Following is the code i am using to solve fun = @(alpha) pwm_equations_multilevel_pso(alpha0,1,2,harmonics) nvars = 3; lb=[0, 0, 0];ub=[deg2rad(90),deg2rad(90),deg2rad(90)]; options = optimoptions('particleswarm','SwarmSize',200,'MaxStallIterations',200) options = optimoptions(options,'PlotFcn',@pswplotbestf); [x,fval,exitflag,output] = particleswarm(fun,nvars,lb,ub,options) where 'pwm_equations_multilevel_pso' is simply as follows function F_dot = pwm_equations_multilevel_pso(alpha,M,harmonic_cancellation,harmonics) F(1) = cos(harmonics(1)*alpha(1)) + cos(harmonics(1)*alpha(2)) - cos(harmonics(1)*alpha(3)); F(2) = cos(harmonics(2)*alpha(1)) + cos(harmonics(2)*alpha(2)) - cos(harmonics(2)*alpha(3)); F(3) = (cos(alpha(1)) + cos(alpha(2)) - cos(alpha(3))) - M; F_dot=dot(F,F) end So the scalar value returned is a dot product of F with itself. I want to minimize F_dot to zero, but when i use PSO i get the following result Unfortunately PSO does not converge to zero, it does not do anything in my case. Obviously I am doing something wrong, but I am not sure what Any help will be appreciated! Rahul Nadgouda https://au.mathworks.com/matlabcentral/profile/authors/6175212-rahul-nadgouda tag:au.mathworks.com,2005:Question/476510 2019-08-17T13:15:19Z 2019-08-18T22:52:03Z How to add a black border to a Title ploted Hello , I'm trying to add a black border around the yellow title letters to better visibility, is that possible?. Thanks. Yuliano Yuliano Moscoso Yarin https://au.mathworks.com/matlabcentral/profile/authors/11513227-yuliano-moscoso-yarin tag:au.mathworks.com,2005:Question/476616 2019-08-18T21:01:35Z 2019-08-18T22:43:25Z inset of matlab figure inside the figure doesnot show new axes label Here is the code I used: figure (3) plot(total_cellcount.time,(prolif.')./total_cellcount.sum_sum_cell_count,'o') xlabel('Time'); ylabel('No. prolif. cells/total No. cells') axes('Position',[.7 .7 .2 .2]) box on plot(total_cellcount.time,prolif,'o') xlabel('Time'); ylabel('No. prolif. cells') The axes label of inset figure is the same as the main figure. How can I fix it? Zeynab Mousavikhamene https://au.mathworks.com/matlabcentral/profile/authors/14179884-zeynab-mousavikhamene tag:au.mathworks.com,2005:Question/476614 2019-08-18T20:40:45Z 2019-08-18T22:39:48Z Arduino Motor Shield Problem I installed Arduino hardware package.I watched tutorial about adafruit motorshield with arduino but my motor shield is V1 .My code is dont play. Kadir Öztürk https://au.mathworks.com/matlabcentral/profile/authors/13057447-kadir-ozturk tag:au.mathworks.com,2005:Question/476617 2019-08-18T21:14:08Z 2019-08-18T22:37:21Z how can call a function Hello everyone, how can i call this function in an other function? i need to plot a, b, c and d: function [o, a, b, c, d] = ObjectiveFunction(X ) a=sum(throughputS, 'all'); b=sum(throughputT, 'all'); c=sum(throughputCN, 'all'); d=sum(throughputCR, 'all'); Thanks alot brahmi ibtissem https://au.mathworks.com/matlabcentral/profile/authors/7283922-brahmi-ibtissem tag:au.mathworks.com,2005:Question/476619 2019-08-18T21:24:25Z 2019-08-18T22:35:17Z Find intersection of two x-y tracks given time element I have two tracks defined by x-y coordinates in which I would like to establish the crossing points. This appears to be relatively easy using several of the submissions on File Exchange such as <https://uk.mathworks.com/matlabcentral/fileexchange/11837-fast-and-robust-curve-intersections Intersection> and <https://uk.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections InterX> . This submission a list of the x and y values of the crossing points. However it doesn’t take into account time. Let me explain.... Suppose my two tracks are for a cat and a mouse. The tracks explain where both the cat and mouse have been as a function of time using x-y coordinates. Let’s now suppose that I know that the cat always trails the mouse - that is to say that the mouse is always ahead of the cat as a function of time, never the other way round. Is there a quick way (like the File Exchange link I show) to calculate only crossing points where the cat crosses the mouses trail, not the mouse crossing the cats trail. One solution would be to return x-y-time triplets which I could then filter to ensure the cat is behind the mouse. But I’m not sure how I could make a fast running function of this nature Mark Jackson https://au.mathworks.com/matlabcentral/profile/authors/4946998-mark-jackson tag:au.mathworks.com,2005:Question/476618 2019-08-18T21:19:46Z 2019-08-18T22:31:03Z Criss - cross game in MATLAB, using matrices. Hello everybody, first of all, I want to thank everyone in MATLAB community and apologise for potential grammatical mistakes. I am the student of the University of applied sciences in Bjelovar, Croatia. Not so long ago, I started using MATLAB. After I discovered this site, I was amazed with people's indepth knowledge, and overall complexity. My problem is creating a criss - cross game using matrices. Basically, I need to create 3x3 matrix with zeros only. Then, first player enters number 1-9, this number represents one field, from top left corner to bottom right corner. When first player enters chosen number (chosen field), MATLAB needs to assing number 1 to that specific location in matrix. Then second player chooses number (field), only now MATLAB needs to assing number 2 to that specific location in matrix. After all iterations are ended, MATLAB needs to declare a winner if there are numbers 1 or 2 in a row. This is program code I had written so far: M1=[0 0 0;0 0 0;0 0 0]; prompt='First player. Enter field.'; prompt2='Second player.Enter field.'; for i = 1:4 a = input(prompt); switch a case 1 M1(1,1)=1; case 2 M1(1,2)=1; case 3 M1(1,3)=1; case 4 M1(2,1)=1; case 5 M1(2,2)=1; case 6 M1(2,3)=1; case 7 M1(3,1)=1; case 8 M1(3,2)=1; case 9 M1(3,3)=1; end a=input(prompt2); switch a case 1 M1(1,1)=2; case 2 M1(1,2)=2; case 3 M1(1,3)=2; case 4 M1(2,1)=2; case 5 M1(2,2)=2; case 6 M1(2,3)=2; case 7 M1(3,1)=2; case 8 M1(3,2)=2; case 9 M1(3,3)=2; end end disp(M1); Marino Weh https://au.mathworks.com/matlabcentral/profile/authors/15976123-marino-weh tag:au.mathworks.com,2005:Question/476582 2019-08-18T13:15:54Z 2019-08-18T22:30:46Z there are more than 1 element satisfy the command in one column, but I only need to count it one time hello, experts, I am new to Matlab community and a beginer to use it I have a dataset (refer as attachment) data = textread('January-2018-Adelaide.csv', '', 'headerlines', 1, 'delimiter', ','); and would like to count how many days satisfy the cammand which is the temerature exceed 41.0 however, in some days, there are more than one temerature exceed 41.0 and if i use n_days_above = numel(find(temperatures>41)); it will be count more than one time (it shows: n_days_above =7, but the correct answer is 3 ) how can I solve this problem? thank you in advanced! data = textread('January-2018-Adelaide.csv', '', 'headerlines', 1, 'delimiter', ','); temperatures = data(:, 4:end); n_days_above = numel(find(temperatures>41)); YU-HAN LIAO https://au.mathworks.com/matlabcentral/profile/authors/15874988-yu-han-liao tag:au.mathworks.com,2005:Question/476620 2019-08-18T21:45:44Z 2019-08-18T22:29:37Z how to use QPBLUR in Matlab? I am trying to solve a quadratic problem with inequalities constraints. followed this :https://web.stanford.edu/group/SOL/dissertations/maes-thesis.pdf the best way is to use QPBLUR because my data set is too large. in that pdf it says: The algorithm is implemented as the QPBLUR solver (Matlab and Fortran 95 versions) but I couldn't find it in matlab. please help me out . how I can use this solver from matlab sherek sharghi https://au.mathworks.com/matlabcentral/profile/authors/15976246-sherek-sharghi tag:au.mathworks.com,2005:Question/476547 2019-08-18T01:47:30Z 2019-08-18T22:24:14Z "Index exceeds matrix dimensions." clear all clc nodos=input('Ingresa la cantidad de nodos del sistema\n n = '); noZ=input('Ingresa la cantidad de lineas del sistema \n NoZ = '); for i=1:noZ %Ciclo para ingresar los valores de la Z de rama. ne(i)=input('Número de referencia del nodo emisor = '); nr(i)=input('Número de referencia del nodo receptor = '); %clc fi=2%('Número de filas de la matriz = '); co=2%2'Número de columnas de la matriz = '); clc disp(['Ingresa la matriz de impedancias de la linea #',num2str(i),':']) for j=1:fi%Filas for jj=1:co%Columnas disp(['El elemento (',num2str(j),',',num2str(jj),')']) Ztramo(j,jj,i)=input(''); end end clc disp(['La matriz de impedancias del tramo #',num2str(i),' es:']) Ztramo% Muestra Z de tramo con ceros. disp(['La matriz de admitancias del tramo #',num2str(i),' es:']) Ytramo(:,:,i)=inv(Ztramo(:,:,i)); Ytramo ybus=diag(0,(nodos*2)-1); end for i=1:noZ %Ciclo para la formación de YBUS k1=ne(:,:,i); k2=nr(:,:,i); ybus(k1,k1)=ybus(k1,k1)+Ytramo(:,:,i); ybus(k2,k2)=ybus(k2,k2)+Ytramo(:,:,i); ybus(k1,k2)=-Ytramo(:,:,i); ybus(k2,k1)=ybus(k1,k2); end clc ybus Eduardo Rojas https://au.mathworks.com/matlabcentral/profile/authors/15973011-eduardo-rojas tag:au.mathworks.com,2005:Question/476438 2019-08-16T17:28:18Z 2019-08-18T22:15:01Z Finding the sum of every nth row ( n is not fixed) Hello, Consider a nx2 matrix M with M= [ 0 4 1 10 1 11 1 20 2 4 2 9 2 8 2 7 . 23 8 23 6 0 8 0 7 1 2 2 5 . . ]; The 1st row refers to hours of the day, i.e. 0,1,...,23 The values of hours per sequence varies, for example the 1st sequence (1st day) has 1 "0" 3 "1" etc while the 2nd sequence (2nd day) has 2 "0" 1 "1" etc. I need to find the sum of the 2nd column per hour and per day. For example, for the 1st day 4 (for "0") 41 (for "1") etc. and for the 2nd day 15 (for "0") 2 (for "1") etc. Thank you very much Best, Pavlos pavlos https://au.mathworks.com/matlabcentral/profile/authors/2882759-pavlos tag:au.mathworks.com,2005:Question/476621 2019-08-18T22:02:23Z 2019-08-18T22:02:23Z How can I make bidirectional search So I did manage to make frame interpolation by using algorithms for motion estimation ( three step, and diamond search) , but they are unidirectional, now im stack cause i need them to be bidirectional (interpolated frame need to be predicted from previouse and current frame). Any ideas how to do that ? Igor Kispeco https://au.mathworks.com/matlabcentral/profile/authors/4305816-igor-kispeco tag:au.mathworks.com,2005:Question/476551 2019-08-18T04:41:17Z 2019-08-18T21:43:02Z lsqcurvefit Error using / Hi, I'm trying to use MATLAB to fit some data using nonlinear least square fitting. When I run my code: xdata = NbO2_219_T'; %NbO2_219_T is a column vector (want a row vector) ydata = NbO2_219_ln_rho'; %NbO2_219_ln_rho is a column vector fun = @(x,xdata) (x(1)*(1 + (sqrt(1 + xdata./x(2)) - 1)/(xdata./x(2))))/sqrt((sqrt(1 + xdata./x(2)) - 1)) + x(3); %x = [x(1) x(2) x(3)] Parameters to solve for x0 = [5 7e-3 -30]; %Initial geusses for parameters x = lsqcurvefit(fun,x0,xdata,ydata) I get the following error: Error using / Matrix dimensions must agree. Error in nonlinearfit_rho_vs_T>@(x,xdata)(x(1)*(1+(sqrt(1+xdata/x(2))-1)/(xdata/x(2))))/sqrt((sqrt(1+xdata/x(2))-1))+x(3) Error in lsqcurvefit (line 213) initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:}); Error in nonlinearfit_rho_vs_T (line 14) x = lsqcurvefit(fun,x0,xdata,ydata) Caused by: Failure in initial objective function evaluation. LSQCURVEFIT cannot continue. Does anyone know what could be the potential cause of this? I tried replacing the '/' with './' but unfortunately it did not solve the issue. Chris Andoh https://au.mathworks.com/matlabcentral/profile/authors/10298272-chris-andoh tag:au.mathworks.com,2005:Question/102434 2010-05-19T13:30:00Z 2019-08-18T21:30:06Z Why do I receive an error writing data to netCDF variable with the unlimited option in MATLAB 7.8 (R2009a)? I am trying to write data to a netCDF variable with infinite dimension in MATLAB 7.8 (R2009a). I execute the following code: nc = netcdf.create(&#39;testfile.nc&#39;, netcdf.getConstant(&#39;NC_CLOBBER&#39;)); %% define unlimited dimension unlim_id = netcdf.defDim(nc, &#39;unlim&#39;, netcdf.getConstant(&#39;NC_UNLIMITED&#39;)); %% define a dimension of length 50 dim_id = netcdf.defDim(nc, &#39;x&#39;, 50); %% define a variable &#39;time&#39; of unlimited dimension t_id = netcdf.defVar(nc, &#39;time&#39;, &#39;double&#39;, unlim_id); %% define a variable &#39;z&#39; that has 2 dimensions z_id = netcdf.defVar(nc, &#39;z&#39;, &#39;double&#39;, [dim_id unlim_id]); netcdf.endDef(nc); I now try putting data into variable &#39;time&#39;: netcdf.putVar(nc, t_id, [1 2 3]); or when I try putting data into variable &#39;z&#39;: netcdf.putVar(nc, z_id, rand(30,20)); I get the following error: ERROR: ??? Error using ==&gt; netcdflib The number of input elements does not match the variable size. MathWorks Support Team https://au.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-team tag:au.mathworks.com,2005:Question/476589 2019-08-18T14:40:12Z 2019-08-18T21:25:10Z how can i generate random number divided by 0.25 from 0 to 10 for example(0.25,7.75,5.50,6.25 ,........)? for example(0.25,7.75,5.50,6.25 ,........) sara anwer https://au.mathworks.com/matlabcentral/profile/authors/12123545-sara-anwer tag:au.mathworks.com,2005:Question/474928 2019-08-05T15:54:05Z 2019-08-18T21:16:39Z How to read in a non-standard formated CSV file containing times and measurments and change the output format? Hi I have a large CSV data file which I want to read in to matlab and correlate data times (shown as TIM in the example below) with various data measurements (ABC, DEF, GHI). The structure of the data file (which I cannot change) is such that the date / time is stated on a single line and the following lines (until the next TIM line) contain measurements taken at the previous time step. Broadly speaking the data format is as follows: TIM, 20190805, 110000 ABC, 123 DEF, 456 GHI, 789 TIM, 20190805, 110001 ABC, 123 DEF, 456 GHI, 789 TIM, 20190805, 110002 ABC, 123 DEF, 456 GHI, 789 The output I want is DATE , TIME , ABC, DEF, GHI 20190805, 110000, 123, 456, 789 20190805, 110001, 123, 456, 789 20190805, 110002, 123, 456, 789 so i can easily correlate times with measurements. The brute force approach would be to loop over every line, save the date / time when it appears and keep reading over the measurements until you reach then next time stamp. Once you hit this, save everything into an array of some flavour (cell etc) with the time step. However, my CSV file is very large so reading through and parsing the whole file line-by-line is VERY slow. Hence I am looking for a quicker way to read in the data and get to the output I want. I first approached this by using the readtable command in MATLAB to get a MATLAB table, then find all the time/date (TIM) rows and use row offsets e.g. ABC = 1, DEF = 2, GHI = 3 etc to filter out the measurement rows. I then end up with four arrays TIM, ABC, DEF, GHI. However, as always, this is proving to be a nightmare due to inconsistencies in the data. Examples of this are TIM, 20190805, 110000 ABC, 123 GHI, 789 DEF, 456 TIM, 20190805, 110001 ABC, 123 GHI, 789 DEF, 456 TIM, 20190805, 110002 ABC, 123 DEF, 456 GHI, 789 (Note that the order of DEF and GHI have been switched in the first two blocks) TIM, 20190805, 110000 ABC, 123 TIM, 20190805, 110000 DEF, 456 GHI, 789 TIM, 20190805, 110001 ABC, 123 DEF, 456 GHI, 789 TIM, 20190805, 110002 ABC, 123 DEF, 456 TIM, 20190805, 110002 GHI, 789 (Note the repeated date / time (TIM) lines with the same times) Any thoughts on a robust reader to transform my data? Thanks in advance Mark Jackson https://au.mathworks.com/matlabcentral/profile/authors/4946998-mark-jackson tag:au.mathworks.com,2005:Question/476615 2019-08-18T20:40:54Z 2019-08-18T21:12:11Z Right-truncating a lognormal distribution Hello, I would like to compute the probability that P(z<a) where z=exp(x*beta+e) and e is distributed iid N(0,sigma^2). I would like to evaluate the CDF of z, i.e., P(e< log(a)-x*beta), for various values of x*beta. However, I know that z cannot take a value greater than a certain number, b. How can I obtain the truncated distribution to evaluate the above probability? Many thanks in advance. bombilibom bilibilibom https://au.mathworks.com/matlabcentral/profile/authors/15974342-bombilibom-bilibilibom tag:au.mathworks.com,2005:Question/476408 2019-08-16T13:36:49Z 2019-08-18T21:08:44Z Select a GPU to be used by a function running in parallel(parfeval) Hello, I am using two GPUs in a GUI postprocessing images live. I am using the 'FramesAcquiredFcn' as a hub to transfer data from the buffer to the CPU RAM memory ('getdata') and launch a 'parfeval' function on GPU postprocessing these data. I have 1 pool with 3 workers initialized (one for the 'FramesAcquiredFcn' and one for each GPU). I can check that when the 'parfeval' function is not finished at the next iteration the second GPU is used instead. Now, I know that using 'wait' I can force the first GPU to be used. However, I would like to split my postprocessing between these two GPUs because one is more powerful than the other. Hence, I would need the first 'parfeval' function to use the GPU1 pass the outputs (using 'afterEach'?) to an other parfeval function using the GPU2. I have read the 'help selectGPU' but could not figure out how to modify it for my purpose. Any help will be welcome. Tutu https://au.mathworks.com/matlabcentral/profile/authors/15418592-tutu tag:au.mathworks.com,2005:Question/181454 2015-03-04T06:52:06Z 2019-08-18T20:59:26Z Adding the mean in a scatter plot Hello, I have 2 columns matrix(x, y) and have plotted them into a scatter plot. I would also like to add a marker (different from the rest of the markers in the scatterplot, e.g. a cross istead of circles) that shows the mean value of x and y. Really thankful for help in this! rej https://au.mathworks.com/matlabcentral/profile/authors/3215670-rej tag:au.mathworks.com,2005:Question/476486 2019-08-17T04:51:06Z 2019-08-18T20:35:13Z Control character error arising only after compiling script to an executable. I am using an application that has the user create configuration files through MATLAB scripts. The user then has to encrypt these configuration files into the application's own file format. The encrypter is provided as a group of p-code files and is simply called in the command window with: encrypt(<filename.m>) Instead of encrypting each file manually, I wrote a script to loop over all the configuration files and encrypt them. Everything works fine if this script is run from the MATLAB editor. However, if I compile the script using MATLAB Compiler through the "deploytool" command, I get an error which causes the executable to stop running because it can't find all the right p-code files. Below is the error I receive: Warning: Control Character '\+' is not valid. See 'doc sprintf' for control characters valid in the format string. I think have a good understanding of what the error means and I believe it would be fixed if the single backslash was replace by a double backslash. The '\+' is referring to the start of the name of a subdirectory located within the p-code encrypter files. This subdirectory contains a p-code function which is required to complete the encryption but obviously this p-code function cannot be called if a previous function cannot cd to this respective directory. My main question is why this only occurs when trying to run my script as an executable and if there are any methods I can try to remedy this error. I cannot change the encryption process since it is all in p-code so I have had some trouble trying to think of how I can go about this. Any help is appreciated. Joe Koszut https://au.mathworks.com/matlabcentral/profile/authors/12658577-joe-koszut tag:au.mathworks.com,2005:Question/476523 2019-08-17T15:38:33Z 2019-08-18T20:34:37Z How i can maximizing parameter in ODE I solve one ODE dx/dt=Na0/((-rA*V)) using code: function dtimedxa = ode_sys (xa,time) Nao=5; k=0.023; Vo=10; epsilon=1; Cao=Nao/Vo; Ca=Cao*(1-xa)/(1+epsilon*xa); p=time*Ca; ra=-k*Ca^2; V=Vo*(1+epsilon*xa); dtimedxa=Nao/((-ra)*V); end and script: range=[0,0.75]; ICs=; [xa,time]=ode23(@ode_sys,range,ICs); figure plot (xa,time(:,1)) title('dependence') xlabel('conversion') ylabel ('time') Is it posible to solve equation above dt/dx=Na0/(-rA*V) maximizing t or p? Thanks in advance. Bosnian King https://au.mathworks.com/matlabcentral/profile/authors/15971765-bosnian-king tag:au.mathworks.com,2005:Question/476571 2019-08-18T10:43:05Z 2019-08-18T20:26:42Z Why did I type the following example in MATLAB, MATLAB shows an error.What's the reason? I type the following example in MATLAB, MATLAB shows an error.What's the reason? mingluo https://au.mathworks.com/matlabcentral/profile/authors/15803787-mingluo tag:au.mathworks.com,2005:Question/476613 2019-08-18T20:21:28Z 2019-08-18T20:21:28Z How do I export data from the embedded code? Hi everyone I'm a building an MPC, to follow an optimal trajectory I have computed, for this I want to embed the code, using the simulink "build model" feature and eventually put it on an ETAS 910. But this is my first experience with this and I can't figure out what block can give me the control, state and reference signal as an output. The "To file" block gives me some data, but when you open the file its either corrupted or contains what I think is raw code.(I have tried export to both csv and xlsx) Any help is much appreciated, as this is a new area for me! Thank you. Kind regards Johan Svendsen Johan Svendsen https://au.mathworks.com/matlabcentral/profile/authors/14465340-johan-svendsen tag:au.mathworks.com,2005:Question/476609 2019-08-18T19:36:46Z 2019-08-18T20:17:49Z How to get the point under mouse click on the plot or histogram? I have an axis object in my application, and I am drawing histogram on that axis object. Is there any event fired when I click a bar on that histogram? If yes How can I intercept that event and get the index of the bar under mouse position? This is not about the script where I can use 'waitforbuttonpress' this is application where I have nowhere to use any wait function without blocking the application. Thanks, in Advance. Hakob Bazoyan https://au.mathworks.com/matlabcentral/profile/authors/14675465-hakob-bazoyan tag:au.mathworks.com,2005:Question/476587 2019-08-18T13:56:08Z 2019-08-18T20:13:37Z having matlab internal error I was facing this error 3 times in the row at the different time step of one run. what doese it mean? please help with this. MATLAB crash file:C:\Users\ADMINI~1\AppData\Local\Temp\matlab_crash_dump.7880-1: -------------------------------------------------------------------------------- std::terminate() detected at Sat Aug 17 04:23:49 2019 -0700 -------------------------------------------------------------------------------- Configuration: Crash Decoding : Disabled - No sandbox or build area path Crash Mode : continue (default) Default Encoding : windows-1252 Deployed : false Graphics Driver : Intel Intel(R) HD Graphics 630 Version 4.5.0 - Build 22.20.16.4749 Graphics card 1 : Intel Corporation ( 0x8086 ) Intel(R) HD Graphics 630 Version 22.20.16.4749 (2017-7-24) Java Version : Java 1.8.0_152-b16 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode MATLAB Architecture : win64 MATLAB Entitlement ID : 6257193 MATLAB Root : C:\Program Files\MATLAB\R2018b MATLAB Version : 9.5.0.944444 (R2018b) OpenGL : hardware Operating System : Microsoft Windows 10 Enterprise Process ID : 7880 Processor ID : x86 Family 6 Model 158 Stepping 9, GenuineIntel Session Key : bac6259a-c728-49fe-a511-1474198ac226 Window System : Version 10.0 (Build 16299) Fault Count: 1 Abnormal termination Register State (captured): RAX = 0000000012a3edd8 RBX = 0000000012a3edd8 RCX = 00000000043f4ee0 RDX = 0000000000000000 RSP = 00000000043f4e50 RBP = 00000000043f8420 RSI = 0000000000000000 RDI = 0000000000000000 R8 = 00007ffc454fe928 R9 = 00007ffc454fe930 R10 = 0000c8a39c0ae694 R11 = 0000000012a2ed6e R12 = 00000000043f5b18 R13 = 000000001d080000 R14 = 0000000012a2ed08 R15 = 00000000043f5550 RIP = 00000000127e292a EFL = 00000206 CS = 0033 FS = 0053 GS = 002b Stack Trace (captured): [ 0] 0x00000000127db2c3 bin\win64\libmwfl.dll+00045763 foundation::core::diag::thread_context::unspecified_bool+00000051 [ 1] 0x00000000127d9288 bin\win64\libmwfl.dll+00037512 foundation::core::diag::stacktrace_base::capture+00000024 [ 2] 0x00000000127ddb80 bin\win64\libmwfl.dll+00056192 foundation::core::diag::symbols::getSymbolAddress+00009632 [ 3] 0x00000000127e165f bin\win64\libmwfl.dll+00071263 foundation::core::diag::is_terminate_message_enabled+00000575 [ 4] 0x000000001920eb3f bin\win64\mcr.dll+01108799 QueryMLFcnTable_mcr+00047535 [ 5] 0x000000001920e277 bin\win64\mcr.dll+01106551 QueryMLFcnTable_mcr+00045287 [ 6] 0x000000001920a2b0 bin\win64\mcr.dll+01090224 QueryMLFcnTable_mcr+00028960 [ 7] 0x000000001920fe36 bin\win64\mcr.dll+01113654 mnSetSegvServiceUrl+00000214 [ 8] 0x00007ffc4d7fadb8 C:\Windows\System32\ucrtbase.dll+00437688 terminate+00000024 [ 9] 0x00007ffc454f19aa C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00006570 _std_terminate+00000010 [ 10] 0x00007ffc454fc1e0 C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00049632 _C_specific_handler+00000560 [ 11] 0x00007ffc454f2a6a C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00010858 _TypeMatch+00000714 [ 12] 0x00007ffc454f1dc6 C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00007622 is_exception_typeof+00000838 [ 13] 0x00007ffc454fb950 C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00047440 _CxxFrameHandler3+00000144 [ 14] 0x00007ffc511b4cbd C:\Windows\SYSTEM32\ntdll.dll+00675005 _chkstk+00000413 [ 15] 0x00007ffc5112e465 C:\Windows\SYSTEM32\ntdll.dll+00124005 RtlUnwindEx+00000885 [ 16] 0x00007ffc454fbcd9 C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00048345 FindAndUnlinkFrame+00000393 [ 17] 0x00007ffc454f2bb9 C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00011193 _TypeMatch+00001049 [ 18] 0x00007ffc454f22e3 C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00008931 is_exception_typeof+00002147 [ 19] 0x00007ffc454f1ec2 C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00007874 is_exception_typeof+00001090 [ 20] 0x00007ffc454fb950 C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00047440 _CxxFrameHandler3+00000144 [ 21] 0x00007ffc511b4c3d C:\Windows\SYSTEM32\ntdll.dll+00674877 _chkstk+00000285 [ 22] 0x00007ffc5112d1b8 C:\Windows\SYSTEM32\ntdll.dll+00119224 RtlWalkFrameChain+00005400 [ 23] 0x00007ffc5112b623 C:\Windows\SYSTEM32\ntdll.dll+00112163 RtlRaiseException+00000771 [ 24] 0x00007ffc4e383fb8 C:\Windows\System32\KERNELBASE.dll+00081848 RaiseException+00000104 [ 25] 0x00007ffc454f44f2 C:\Program Files\MATLAB\R2018b\bin\win64\VCRUNTIME140.dll+00017650 CxxThrowException+00000194 [ 26] 0x0000000012aa5de8 bin\win64\pgo\libmx.dll+00220648 mxArray_tag::operator delete+00025192 [ 27] 0x0000000012aa9695 bin\win64\pgo\libmx.dll+00235157 mxArray_tag::operator delete+00039701 [ 28] 0x0000000012a73c6d bin\win64\pgo\libmx.dll+00015469 matrix::detail::noninlined::mx_array_api::mxUnshare+00000513 [ 29] 0x0000000012a8010a bin\win64\pgo\libmx.dll+00065802 matrix::detail::noninlined::mx_array_api::mxUnshareEx+00000030 [ 30] 0x0000000012aa5730 bin\win64\pgo\libmx.dll+00218928 mxArray_tag::operator delete+00023472 [ 31] 0x000000001d086591 bin\win64\pgo\libmwlxetypes.dll+00026001 MathWorks::lxe::xvalue::operator=+00000145 [ 32] 0x000000001a26ed9d bin\win64\pgo\m_lxe.dll+01371549 mwboost::archive::detail::iserializer<mwboost::archive::binaryTerm_iarchive,MathWorks::lxe::function_descriptor>::load_object_data+00489569 [ 33] 0x000000001a17aa30 bin\win64\pgo\m_lxe.dll+00371248 [ 34] 0x000000001a178e1c bin\win64\pgo\m_lxe.dll+00364060 [ 35] 0x000000001a18b265 bin\win64\pgo\m_lxe.dll+00438885 [ 36] 0x000000001a18a88c bin\win64\pgo\m_lxe.dll+00436364 [ 37] 0x000000001a188779 bin\win64\pgo\m_lxe.dll+00427897 [ 38] 0x000000001a1890eb bin\win64\pgo\m_lxe.dll+00430315 [ 39] 0x000000001a188a49 bin\win64\pgo\m_lxe.dll+00428617 [ 40] 0x000000001935e007 bin\win64\pgo\m_dispatcher.dll+00057351 Mfh_file::dispatch_fh_impl+00001111 [ 41] 0x000000001935da9e bin\win64\pgo\m_dispatcher.dll+00055966 Mfh_file::dispatch_fh+00000062 [ 42] 0x000000001a174ead bin\win64\pgo\m_lxe.dll+00347821 [ 43] 0x000000001a30e9b6 bin\win64\pgo\m_lxe.dll+02025910 MathWorks::lxe::ShutdownLxeEngine+00004034 [ 44] 0x000000001a26fd3c bin\win64\pgo\m_lxe.dll+01375548 mwboost::archive::detail::iserializer<mwboost::archive::binaryTerm_iarchive,MathWorks::lxe::function_descriptor>::load_object_data+00493568 [ 45] 0x000000001a27091c bin\win64\pgo\m_lxe.dll+01378588 mwboost::archive::detail::iserializer<mwboost::archive::binaryTerm_iarchive,MathWorks::lxe::function_descriptor>::load_object_data+00496608 [ 46] 0x000000001a271c92 bin\win64\pgo\m_lxe.dll+01383570 mwboost::archive::detail::iserializer<mwboost::archive::binaryTerm_iarchive,MathWorks::lxe::function_descriptor>::load_object_data+00501590 [ 47] 0x000000001a2728f8 bin\win64\pgo\m_lxe.dll+01386744 mwboost::archive::detail::iserializer<mwboost::archive::binaryTerm_iarchive,MathWorks::lxe::function_descriptor>::load_object_data+00504764 [ 48] 0x000000001a271ddf bin\win64\pgo\m_lxe.dll+01383903 mwboost::archive::detail::iserializer<mwboost::archive::binaryTerm_iarchive,MathWorks::lxe::function_descriptor>::load_object_data+00501923 [ 49] 0x000000001a271ede bin\win64\pgo\m_lxe.dll+01384158 mwboost::archive::detail::iserializer<mwboost::archive::binaryTerm_iarchive,MathWorks::lxe::function_descriptor>::load_object_data+00502178 [ 50] 0x000000001a179a7d bin\win64\pgo\m_lxe.dll+00367229 [ 51] 0x000000001a18b265 bin\win64\pgo\m_lxe.dll+00438885 [ 52] 0x000000001a18a88c bin\win64\pgo\m_lxe.dll+00436364 [ 53] 0x000000001a1842a1 bin\win64\pgo\m_lxe.dll+00410273 [ 54] 0x000000001a1839c6 bin\win64\pgo\m_lxe.dll+00408006 [ 55] 0x000000001a183ace bin\win64\pgo\m_lxe.dll+00408270 [ 56] 0x000000001a363780 bin\win64\pgo\m_lxe.dll+02373504 mwboost::archive::detail::oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::CodeClearEvent>::oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::CodeClearEvent>+00012824 [ 57] 0x000000001a36372e bin\win64\pgo\m_lxe.dll+02373422 mwboost::archive::detail::oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::CodeClearEvent>::oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::CodeClearEvent>+00012742 [ 58] 0x000000001a2434fd bin\win64\pgo\m_lxe.dll+01193213 mwboost::archive::detail::iserializer<mwboost::archive::binaryTerm_iarchive,MathWorks::lxe::function_descriptor>::load_object_data+00311233 [ 59] 0x00000000195b69e7 bin\win64\pgo\m_interpreter.dll+00354791 inEvalCmdWithLocalReturn+00000063 [ 60] 0x00000000fb610388 bin\win64\libmwbridge.dll+00131976 mnParser+00001304 [ 61] 0x0000000019153618 bin\win64\mcr.dll+00341528 mcr::runtime::setInterpreterThreadSingletonToCurrent+00020808 [ 62] 0x000000001915414d bin\win64\mcr.dll+00344397 mcr::runtime::setInterpreterThreadSingletonToCurrent+00023677 [ 63] 0x000000001911b1ba bin\win64\mcr.dll+00111034 mcrOptions::set_use_license_manager+00075498 [ 64] 0x0000000019136e74 bin\win64\mcr.dll+00224884 mcrOptions::set_use_license_manager+00189348 [ 65] 0x00000000fd02cfee bin\win64\iqm.dll+00643054 iqm::PackagedTaskPlugin::execute+00000894 [ 66] 0x00000000fd02ce63 bin\win64\iqm.dll+00642659 iqm::PackagedTaskPlugin::execute+00000499 [ 67] 0x00000000fcffcc07 bin\win64\iqm.dll+00445447 iqm::Iqm::setupIqmFcnPtrs+00076215 [ 68] 0x00000000fcffcc59 bin\win64\iqm.dll+00445529 iqm::Iqm::setupIqmFcnPtrs+00076297 [ 69] 0x00000000fcffca16 bin\win64\iqm.dll+00444950 iqm::Iqm::setupIqmFcnPtrs+00075718 [ 70] 0x00000000fcfd9748 bin\win64\iqm.dll+00300872 iqm::Iqm::deliver+00005880 [ 71] 0x00000000fcfd8eef bin\win64\iqm.dll+00298735 iqm::Iqm::deliver+00003743 [ 72] 0x00000000fcfdac0d bin\win64\iqm.dll+00306189 iqm::Iqm::deliver+00011197 [ 73] 0x0000000100203775 bin\win64\libmwservices.dll+02176885 services::system_events::PpeDispatchHook::dispatchOne+00036213 [ 74] 0x0000000100212a63 bin\win64\libmwservices.dll+02239075 sysq::addProcessPendingEventsUnitTestHook+00006035 [ 75] 0x0000000100214310 bin\win64\libmwservices.dll+02245392 sysq::getCondition+00004208 [ 76] 0x000000010021596d bin\win64\libmwservices.dll+02251117 svWS_ProcessPendingEvents+00000221 [ 77] 0x0000000019157724 bin\win64\mcr.dll+00358180 mcr::runtime::setInterpreterThreadSingletonToCurrent+00037460 [ 78] 0x0000000019157f16 bin\win64\mcr.dll+00360214 mcr::runtime::setInterpreterThreadSingletonToCurrent+00039494 [ 79] 0x000000001914cabf bin\win64\mcr.dll+00314047 mcr_process_events+00001007 [ 80] 0x000000001905d040 bin\win64\MVMLocal.dll+00380992 mvm_server::inproc::LocalFactory::terminate+00177312 [ 81] 0x00000000fa9d9480 bin\win64\mvm.dll+01741952 mvm::detail::SessionImpl::initWithOptions+00000592 [ 82] 0x00000000fa9da170 bin\win64\mvm.dll+01745264 mvm::detail::SessionImpl::runMain+00000128 [ 83] 0x00000000fa9da395 bin\win64\mvm.dll+01745813 mvm::detail::SessionImpl::runMatlabDesktop+00000261 [ 84] 0x0000000140007036 bin\win64\MATLAB.exe+00028726 mwboost::serialization::singleton_module::unlock+00000966 [ 85] 0x0000000140007f13 bin\win64\MATLAB.exe+00032531 mwboost::serialization::singleton_module::unlock+00004771 [ 86] 0x00007ffc4ea41fe4 C:\Windows\System32\KERNEL32.DLL+00073700 BaseThreadInitThunk+00000020 [ 87] 0x00007ffc5117ef91 C:\Windows\SYSTEM32\ntdll.dll+00454545 RtlUserThreadStart+00000033 pooya aghaee https://au.mathworks.com/matlabcentral/profile/authors/15635672-pooya-aghaee tag:au.mathworks.com,2005:Question/476596 2019-08-18T16:06:31Z 2019-08-18T20:03:50Z How to convert the text file (1x290400) to image as shown as below? After I done simulatation, ModelSim gives me an output image file in text file format when doing the convolution neutral network. However, the output image in text file is 1 column vector. (1x290400) Community have an example codes to convert the 1 column vector text file to become an image like above (55x55x96)?There is 96 pictures in 1 output picture and each size is 55x55 Please help me and thank a lot.. Tham Wei Jian https://au.mathworks.com/matlabcentral/profile/authors/15051338-tham-wei-jian tag:au.mathworks.com,2005:Question/476612 2019-08-18T20:01:19Z 2019-08-18T20:01:19Z LSTM with 2 dimensional dependencies for multiple inputs Hi, I'm having troubles figuring out if the data model that I'm working on is correct, this is not a matlab question per sé although I'm working in matlab. My idea is to try to train a regression LSTM network to predict the positions of multiple objects on a plane for a "naval battle" kind of game. Let's say we have 4 "boats" with a known position If any of the boats moves, the others will move. The purpose of the movement and why I choose an LSTM are not relevant here, let me just say that I've put some thought on it and I think that this will be the best solution. I have a training set consisting on multiple positions for each boat in the form: B1 B2 B3 B4 T1 x1,y1 x2,y2 x3,y3 x4,y4 T2 x1,y1 x2,y2 x3,y3 x4,y4 T3 x1,y1 x2,y2 x3,y3 x4,y4 T4 x1,y1 x2,y2 x3,y3 x4,y4 T5 x1,y1 x2,y2 x3,y3 x4,y4 T6 x1,y1 x2,y2 x3,y3 x4,y4 The sequence here is given by T and each boat position is dependent of the remaining boats i.e. boat 3 moves then all the others adjust their position too. In this example the input/output training set will be (i think): T1 -> T2 T2 -> T3 T3 -> T4 T5 -> T6 My main doubt about the data model is if I create an LSTM with (in this case) 8 inputs and 8 outputs will the network "learn" the dependency between the boats? The reason I'm asking this here is because although there's plenty information about LSTM it was really hard for me to find information about the data models used in this kind of problems (or even if it's possible to use an LSTM with this kind of model). Any suggestions or feedback will be greatly apreciated, thank you for your time. juan pedrosa https://au.mathworks.com/matlabcentral/profile/authors/2853885-juan-pedrosa tag:au.mathworks.com,2005:Question/476610 2019-08-18T19:44:47Z 2019-08-18T19:55:19Z Creating means in a table for a specific subnum Hi, I have a table with 10 variables and 3 other descriptor variables (Subnum, Condition , Trial ). So each condition has 4 trials. I want to create means across trials per Subnum. So it would be 20 means per Subnum [2 per each variable becasue of the 2 conditions]. I would be perfect if I can create 2 seperate matricies per Subnum with a row of 10 means since I have to input that variable into another script. I'm new to MATLAB so I appreciate any help. Thanks, Edward Lannon https://au.mathworks.com/matlabcentral/profile/authors/15920970-edward-lannon tag:au.mathworks.com,2005:Question/476598 2019-08-18T16:50:55Z 2019-08-18T19:50:24Z How to make command line free while a program rans? Imagine, I made a program that contineously executes loop FOR-END (a Watch, for example). I'd like to run another program while the first one is still running. However, the command line >> is busy. How to "free" it? Of course, this is the problem of parallel computing. I am a newbile in it now. As far as I learned, there are several ways to start parallelization, either ">> pmode start" or ">> pool = parpool(2)". (I have two 'Workers'). Do I follow the right way? After ">> pmode start" we get two-splitted Window with Lab1 and Lab2. How to submit a job to only one of them? Looking forward, Yevgeny Yevgeny Gayev https://au.mathworks.com/matlabcentral/profile/authors/589999-yevgeny-gayev tag:au.mathworks.com,2005:Question/476611 2019-08-18T19:46:53Z 2019-08-18T19:49:46Z Publish a file along with a file that has function called from another file I want to publish main file,for example say 'one.m' which includes a function that has been called from another file say 'two.m'. Now when I publish 'one.m' I want the 'two.m' to be publish in the file. Lucas Vacus https://au.mathworks.com/matlabcentral/profile/authors/15912586-lucas-vacus tag:au.mathworks.com,2005:Question/476590 2019-08-18T14:49:22Z 2019-08-18T19:47:51Z ERROR came as "Index exceeds matrix dimensions". %% When I incorporate 3 eqns, ERROR came as "Index exceeds matrix dimensions". %%Here I have initial condition f=[0 0 0 ], BC: gl=[coswt t t], gr =[0 0 0 ]. What next? Here is my trial: H=10;R=5;Pr=1;G1=5;G2=5;Kc=1;Sc=0.22;wt=pi/2;Q=H-(R/Pr); xl=0; xr=5; % x domain [xl,xr] J = 10; % J: number of division for x dx = (xr-xl)/ J; % dx: mesh size tf = 01; % final simulation time Nt = 100; % Nt: number of time steps dt = tf/Nt; mu = dt/(dx)^2; % Evaluate the initial conditions x = xl : dx : xr; % generate the grid point % f(1:J+1) since array index starts from 1 f1 = 0;f2 = 0;f3 = 0; %%%I.C % store the solution at all grid points for all time steps u = zeros(J+1,Nt); v = zeros(J+1,Nt); w = zeros(J+1,Nt); U=[u; v; w]; % Find the approximate solution at each time step for n = 1:Nt t = n*dt; % current time % boundary condition at left side gl = [cos(wt); t; t]; % boundary condition at right side gr = [0; 0; 0]; if n==1 % first time step for j=2:J % interior nodes u(j,n) = (1+dt*Q)*f1(j) + dt*(G1*f2(j)+G2*f3(j))+mu*(f1(j+1)-2*f1(j)+f1(j-1)); v(j,n) = (1+dt*Q)*f2(j) + (mu/Pr)*(f2(j+1)-2*f2(j)+f2(j-1)); w(j,n) = (1-dt*Kc)*f3(j) + (mu/Sc)*(f3(j+1)-2*f3(j)+f3(j-1)); U=[u(j,n) v(j,n) w(j,n)]; end U(1,n) = gl; % the left-end point U(J+1,n) = gr; % the right-end point else for j=2:J % interior nodes u(j,n)= (1+dt*Q)*u(j,n-1)+ dt*(G1*v(j,n-1)+G2*w(j,n-1))+ mu*(u(j+1,n-1)-2*u(j,n-1)+u(j-1,n-1)); v(j,n)= (1+dt*Q)*v(j,n-1)+ (mu/Pr)*(v(j+1,n-1)-2*v(j,n-1)+v(j-1,n-1)); w(j,n)= (1+dt*Q)*w(j,n-1)+ (mu/Sc)*(w(j+1,n-1)-2*w(j,n-1)+w(j-1,n-1)); U=[u(j,n) v(j,n) w(j,n)]; end U(1,n) = gl; % the left-end point U(J+1,n) = gr; % the right-end point end end % Plot the results tt = dt : dt : Nt*dt; figure(1) plot(x,u) hold on MINATI PATRA https://au.mathworks.com/matlabcentral/profile/authors/12692023-minati-patra tag:au.mathworks.com,2005:Question/476607 2019-08-18T18:47:19Z 2019-08-18T19:37:41Z inputparser fails to accept correct value I'm currently trying to get the inputparser for my function to work. My code looks like this: function [] = Test2 (BW,varargin) defMethod = 2; p = inputParser; validImage = @(x) islogical(x); addRequired(p,'BW',validImage); addParameter(p,'method',defMethod,@(x) isinteger(x) && (x<3) && (x>0)); parse(p,BW,varargin{:}); Running this codes yields the following result: Test2(BW,'method',1); The value of 'method' is invalid. It must satisfy the function: @(x)isinteger(x)&&(x<3)&&(x>0). Does anyone know what is causing this behaviour? Ty for your help! xCuse https://au.mathworks.com/matlabcentral/profile/authors/11909708-xcuse