https://kr.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-01-23T00:17:45Ztag:kr.mathworks.com,2005:Question/3784562018-01-22T23:45:21Z2018-01-23T00:17:45ZTime-space plot with meshgrid?<p>I am given a table with three columns</p><pre class="language-matlab">x t color
0 0 10
0.1 0 9
0.2 0 11
0.3 0 3
0 0.1 10
0.1 0.1 9
0.2 0.1 11
0.3 0.1 3
</pre><p>The table is given by a variable P. so that x=P(:,1), t=P(:,2), color=P(:,3).</p><p>I want to make a 2D plot in which the x axis is x, the y axis is t, and every point (x,t) is colored according to the values of P(:,3) (preferably in a grey scale).</p><p>I know that in order to make a plot, I need to use meshgrid for x and t. But how can I make the "color" in accordance with the values after using the meshgrid?</p><p>Hope I made myself clear</p><p>Thanks in advance !</p>Johnsonhttps://kr.mathworks.com/matlabcentral/profile/authors/5550250-johnsontag:kr.mathworks.com,2005:Question/3784572018-01-23T00:16:33Z2018-01-23T00:16:33ZHow to resume training a ClassificationBaggedEnsemble object with new data ??<p>I built Random forest for classification using fitcensemble and trained it with some data (data1) and got ClassificationBaggedEnsemble object (ens). Now I have some more data (data2) and so I want to resume (continue) training this ensemble (ens) with this NEW data.. Can I do so? if yes, then how please??
Thanks in advance..</p>Nada Sherifhttps://kr.mathworks.com/matlabcentral/profile/authors/11527792-nada-sheriftag:kr.mathworks.com,2005:Question/3783362018-01-22T12:43:26Z2018-01-23T00:11:26ZUndefined function or variable<p>that is the whole code which should get face detection with distance</p><pre> load('callast.mat');</pre><pre> double faceDetector();
vid = videoinput('macvideo', 1, 'YCbCr422_1280x960');%left
vid2 = videoinput('macvideo', 3, 'YCbCr422_1280x960');%right</pre><pre> triggerconfig([vid vid2],'manual');
vid2.FramesPerTrigger = 10;
vid.FramesPerTrigger = 10;</pre><pre class="language-matlab">start([vid vid2]);
pause(1)
</pre><pre> trigger([vid vid2]);</pre><pre> I1 = getsnapshot(vid);
I2 = getsnapshot(vid2);</pre><pre> % I1 = undistortImage(T1,stereoParams.CameraParameters1);
%I2 = undistortImage(T2,stereoParams.CameraParameters2);</pre><pre> faceDetector = vision.CascadeObjectDetector;</pre><pre> face1 = faceDetector(I1);
face2 = faceDetector(I2);</pre><pre> center1 = face1(1:2) + face1(3:4)/2;</pre><pre> center2 = face2(1:2) + face2(3:4)/2;</pre><pre> point3d = triangulate(center1, center2, stereoParams);
distanceInMeters = norm(point3d)/1000;</pre><pre> distanceAsString = sprintf('%0.2f meters', distanceInMeters);
I1 = insertObjectAnnotation(I1,'rectangle',face1,distanceAsString,'FontSize',18);
I2 = insertObjectAnnotation(I2,'rectangle',face2, distanceAsString,'FontSize',18);
I1 = insertShape(I1,'FilledRectangle',face1);
I2 = insertShape(I2,'FilledRectangle',face2);</pre><pre> imshowpair(I1, I2, 'montage');</pre><p>the error</p><pre> Undefined function or variable 'stereoParams'.</pre><pre> point3d = triangulate(center1, center2, stereoParams);</pre>ahmed nasrhttps://kr.mathworks.com/matlabcentral/profile/authors/8930187-ahmed-nasrtag:kr.mathworks.com,2005:Question/2318082015-07-30T18:07:23Z2018-01-23T00:00:32ZProblem with rectify StereoImages<p>I want to do a 3D reconstruction from two images from the same camera. I used the Stereo Camera Calibrator App on Matlab R2015a in order to calibrate the camera. The calibration seems to work fine :</p><img src = "/matlabcentral/answers/uploaded_files/34918/StereoCameraCalibration.jpg"><p>Then I used the example from the help to do the 3D reconstruction.</p><pre class="language-matlab">load('Param_test8.mat') % loads the camera parameters
% Read in the stereo pair of images.
I1 = imread('Cam1/Camera1_img1.tif');
I2 = imread('Cam2/Camera2_img1.tif');
% Rectify the images.
[J1, J2] = rectifyStereoImages(I1, I2, stereoParams,'cubic','OutputView','full');
</pre><p>However, there is a problem when I run the rectifyStereoImages, since the two images are then positioned very far from each other :</p><img src = "/matlabcentral/answers/uploaded_files/34919/BeforCalib.jpg"><img src = "/matlabcentral/answers/uploaded_files/34920/AfterCalib.jpg"><p>I don't understand where the problem is, since the stereo calibration manages to position the cameras and the checkerboards very well. I tried different positions for the camera, and different images to reconstruct, but I don't know where the problem is.</p>MJ MJhttps://kr.mathworks.com/matlabcentral/profile/authors/6735394-mj-mjtag:kr.mathworks.com,2005:Question/3782692018-01-22T06:12:48Z2018-01-23T00:00:04Zaxis command fails for log scale<pre class="language-matlab">figure
plot([1 2], [1 2])
axis([0 3 0 3])
axis(gca)
set(gca,'yscale','log')
%axis auto
axis(gca)
</pre><p>The second axis command does not return the correct value. It returns zero for the min Y axis limit, and does not reflect any of the changes from switching to the log scale. Including the axis auto function is a partial workaround for this example, but for some reason does not work the same way in my (very complicated) example.</p>Charleshttps://kr.mathworks.com/matlabcentral/profile/authors/9260291-charlestag:kr.mathworks.com,2005:Question/3277932017-03-02T20:43:12Z2018-01-22T23:57:26Zcmd+0 keyboard shortcut from Live Editor to Command Window<p>This shortcut works if I'm in a regular Editor window, but not when I'm in a Live Editor. Also, from the Command Window, shift+cmd+0 takes me back to the Live Editor just fine. I am using R2016b on a fully updated Mac.</p>Andrew Metcalfhttps://kr.mathworks.com/matlabcentral/profile/authors/515846-andrew-metcalftag:kr.mathworks.com,2005:Question/3783432018-01-22T13:27:03Z2018-01-22T23:47:47ZHow to get values from structure array<p>Hello. I wonder how to get values from structure array, in my case. I know that second line is: incorrect--possibly unbalanced (, {, or [.
Code:</p><pre class="language-matlab">Pose = rget( Kawasaki, 'pose');
getPoseValue =(Pose.x,Pose.y,Pose.z,Pose.o,Pose.t);
rset( Kawasaki, 'base', rpoint(getPoseValue) );
</pre><p>This is how it should be done with constant values. I want to get fresh values from pose of my robot.</p><p>Code2:</p><pre class="language-matlab">%rset( Kawasaki, 'base',
%rpoint(177.957,349.963,-229.418,15.983,179.610,-162.582) );
</pre><img src = "/matlabcentral/answers/uploaded_files/102060/2.PNG">Damianhttps://kr.mathworks.com/matlabcentral/profile/authors/9070949-damiantag:kr.mathworks.com,2005:Question/3784552018-01-22T23:31:19Z2018-01-22T23:44:24ZI want to understand the meaning(Syntax) of this line. Someone please explaiin what conditions are being used and what does it exactly mean in terms of variables used<pre> Kf(fmag<=1) = ((1-(nimage*magnification*fth(fmag<=1)).^2)</pre>Sagar Saxenahttps://kr.mathworks.com/matlabcentral/profile/authors/7588931-sagar-saxenatag:kr.mathworks.com,2005:Question/3784492018-01-22T23:11:46Z2018-01-22T23:43:18ZDoes anyone know what is the input argument in line 3 mean?<img src = "/matlabcentral/answers/uploaded_files/102120/QQ%E5%9B%BE%E7%89%8720180122160944.png"><p>it is a functional file, and I tried to run it, but it told me there is a error in line3. Someone plz helps me...TY!</p>CodeElinesahttps://kr.mathworks.com/matlabcentral/profile/authors/11898003-codeelinesatag:kr.mathworks.com,2005:Question/3784522018-01-22T23:14:21Z2018-01-22T23:25:38ZHow to load a variable name from one function to another?<p>Hi, I am writing a script in which I call 4 separate functions. I am using the following:</p><pre class="language-matlab">function dat = run_experiment(varargin)
dat.subj = input('Enter Participant Code here');
</pre><pre class="language-matlab">run_test
run_introduction
run_prepost_test
run_training
</pre><pre class="language-matlab">end
</pre><p>However, dat.subj is called upon in each function in order to save the filename based on which test it is and it uses the current time. For example, this is in run_introduction:</p><pre class="language-matlab">dat.fileName = [dat.subj '_' dat.test_type '_' dat.timeNow '.mat'];
</pre><p>Every time I run the run_experiment and enter a participant ID for dat.subj, it doesnt seem to carry over when run_introduction begins. I get the error:</p><p>'Reference to non-existent field 'subj'.</p><p>Does anyone have any tips on how to call a variable from a different function? I cannot load it from the workspace, since the file it creates is contingent on the subject ID and the time now.</p><p>Thanks!</p>Katrina Simonhttps://kr.mathworks.com/matlabcentral/profile/authors/9079230-katrina-simontag:kr.mathworks.com,2005:Question/3784132018-01-22T18:33:22Z2018-01-22T23:23:10ZHow to create triangular lattice from two points?<p>Hey,</p><p>Let us say you have an m-by-n matrix, and in this matrix there are two points, A(x,y) and B(x,y). Can anyone help me figure out how to construct a triangular lattice of equilateral triangles where A and B are two of the vertices?</p><p>That is, if the line between A and B is one side of an equilatereal triangle, then point C will be located at equal distance from A and B, forming angles of 60 degrees. A point, D, will again form a triangle with points C and B and so on (see image).I want a code to find all vertices of such a triangular lattice within the boundaries of the matrix.</p><p>Any help is appreciated.</p><img src = "/matlabcentral/answers/uploaded_files/102089/pic.png"><p>Thanks</p>OHhttps://kr.mathworks.com/matlabcentral/profile/authors/4264628-ohtag:kr.mathworks.com,2005:Question/3784542018-01-22T23:15:55Z2018-01-22T23:15:55ZHow to use Legacy Code Tool?<p>I have the following example C code:</p><p><b>void vdptop_vdpmult(real_T rtu_In1, real_T rtu_In2, rtB_vdptop_vdpmult *localB)</b></p><p>I am not sure how to handle the "rtB_vdptop_vdpmult *localB" in Legacy Code Tool. Is it an input/output/dwork vector?</p>Khoi Ngohttps://kr.mathworks.com/matlabcentral/profile/authors/6227862-khoi-ngotag:kr.mathworks.com,2005:Question/3784532018-01-22T23:15:12Z2018-01-22T23:15:12ZTo build Random Forest, which should I use: treeBagger or fitcensemble ??<p>To build a Random Forest for classification task, which should be MORE efficient and accurate: treeBagger or fitcensemble ?? and why?
Thanks in advance..</p>Nada Sherifhttps://kr.mathworks.com/matlabcentral/profile/authors/11527792-nada-sheriftag:kr.mathworks.com,2005:Question/3784512018-01-22T23:14:12Z2018-01-22T23:14:12ZHow can I apply sgolay derivatives to a matrix of signals<p>Dear all,</p><p>My first post here. Thank you for helping me out!</p><p>I am trying to calculate derivatives of a signal, using sgolay filtering, as the signals are slightly noisy. I have a working function, see below.</p><p>However, this uses loops to loop through the individual signals. I would like to create it as a matrix operation, if this makes sense from a performance point of view. The signals are typically 2000 elements long. A dataset may contain a few hundred of these signals. I will use the script on different places so it may have 20 implementations in the final workflow.</p><p><b>So, the questions are</b>:</p><ul><li>Does it make sense to rework this to a matrix operation?</li><li>Can someone help me with the re-work of the code? I am absolutely lost..</li></ul><p><b>Current script:</b></p><pre class="language-matlab">function [derivatives] = JF_savitzky_derivative(spectra, order, framelen, returnorder)
</pre><pre> % create return data array
derivatives = spectra;
derivatives(:,:) = 0;</pre><pre> % define input
sizes = size(spectra);
numspectra = sizes(1);
numbands = sizes(2);</pre><pre> % Create the filter
[b,g] = sgolay(order,framelen);</pre><pre> % create the temporary valuestore
dx = zeros(numbands,returnorder+1);</pre><pre> % Set the spacing between measurements
dt = 1;</pre><pre> % for each spectrum run the filter
for spectrum = 1:length(spectra(:,1))</pre><pre> x=spectra(spectrum,:);</pre><pre> for p = 0:returnorder
dx(:,p+1) = conv(x, factorial(p)/(-dt)^p * g(:,p+1), 'same');
end</pre><pre> derivatives(spectrum,:) = dx(:,returnorder+1);</pre><pre> end</pre><pre> end</pre>Jellehttps://kr.mathworks.com/matlabcentral/profile/authors/586239-jelletag:kr.mathworks.com,2005:Question/3784502018-01-22T23:12:57Z2018-01-22T23:12:57ZHow do you convert generated C code from a Simulink model reference back into a form which can be used in Simulink?<p>I have generated C code from a Simulink reference model but not the Simulink code (the author cannot be contacted). My question is: what is the best way to convert these code into a form which can readily be used in Simulink again?</p>Khoi Ngohttps://kr.mathworks.com/matlabcentral/profile/authors/6227862-khoi-ngotag:kr.mathworks.com,2005:Question/3784482018-01-22T23:11:19Z2018-01-22T23:11:19ZWarning: Matrix is singular, close to singular or badly scaled.<p>I am trying to draw a bifurcation diagram. The code gives me the following warning:
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN.
> In ode15s (line 589)
> In NewBifur3 (line 21)</p><pre> clear; %clc;
figure
set(0,'DefaultAxesFontSize',15)
E=0.7; global K;
Krange = 0.01:0.005:2.5;
k = 0; tspan = 0:0.01:2500;
ymax = [];
ymin = [];
yeq = [];
for K = Krange
j = 1; h=1; g=1; k = k + 1;
f = @(t,x) [1.2*x(1)*(1-x(1)/(min(K*(1+E*sin(x(3))),(0.025-0.03*x(2))/0.0038)))-0.81*x(1)*x(2)/(0.25+x(1));0.8*min(1,((0.025-0.03*x(2))/x(1))/0.03)*0.81*x(1)*x(2)/(0.25+x(1))-0.25*x(2);2*pi/365 ]; % Preypred system
x0 = [0.5 0.25 0];
k = k + 1;
[t,x] = ode15s(f,tspan,x0);
count = find(t>100);
x = x(count,:);
j = 1; h=1; g=1;
n = length(x(:,2));
for i=2 : n-1
if (x(i-1,2)+eps) < x(i,2) && x(i,2) > (x(i+1,2)+eps)
ymax(k,j)=x(i,2);
j=j+1;
elseif (x(i-1,2)+eps) > x(i,2) && x(i,2) < (x(i+1,2)+eps)
ymin(k,h)=x(i,2);
h=h+1;
elseif (x(i-1,2)+eps) == x(i,2) && x(i,2) == (x(i+1,2)+eps)
yeq(k,g)=x(i,2);
g=g+1;
end
end
if j>1
plot(K,ymax(k,1:j-1),'k.','MarkerSize',1.5); hold on;
end </pre><pre> if h>1
plot(K,ymin(k,1:h-1),'k.','MarkerSize',1.5); hold on;
end</pre><pre> if g>1
plot(K,yeq(k,1:g-1),'k.''MarkerSize',1.5); hold on;
end
hold on,
end
xlabel('K_0 (mg C/L)');
ylabel('y (mg C/L)'); </pre><p>Could you please help me to fix it?</p>LALE ASIKhttps://kr.mathworks.com/matlabcentral/profile/authors/6865216-lale-asiktag:kr.mathworks.com,2005:Question/3784452018-01-22T23:00:56Z2018-01-22T23:10:03ZHow do i plot multiple array?<pre class="language-matlab">clear; close all; clc; commandwindow;
load timeh
h=Height(1:5,1:6)
h1=Height(1,1:191)
h2=Height(2,1:191)
h3=Height(3,1:191)
h4=Height(4,1:191)
h5=Height(5,1:191)
t=0:.1:19
plot(t,h1)
</pre><p>Timeh is a file containing the information that needs plotted. Where am i going wrong?</p>kyle dukehttps://kr.mathworks.com/matlabcentral/profile/authors/10787007-kyle-duketag:kr.mathworks.com,2005:Question/3778902018-01-19T05:48:08Z2018-01-22T23:08:28ZIs there a built-in class for Random Forest in matlab 2016a that I can start training and testing ?<p>Dose there a ready made Random forest in the matlab 2016a toolbox that I can use by starting training it with my .mat data ??</p>Nada Sherifhttps://kr.mathworks.com/matlabcentral/profile/authors/11527792-nada-sheriftag:kr.mathworks.com,2005:Question/3784462018-01-22T23:01:15Z2018-01-22T23:05:40ZHow to get a and b using fit(x,y,power1)<p>I have XY data and fit it with y=ax^b. I use f = fit(x,y,power1) but don't know how to get "a" and "b" to continue working with them. f(1) gives a, [a,b] = fit(x,y,power1) doesn't help also.</p>Elyanov Artyomhttps://kr.mathworks.com/matlabcentral/profile/authors/9763690-elyanov-artyomtag:kr.mathworks.com,2005:Question/3388092017-05-05T01:18:02Z2018-01-22T23:04:05ZFinding x,y coordinates of pixel by RGB color value<p>Hi,
Is there a reverse impixel function? I want to find the x and y coordinates of pixels in a color image by searching for them only with a RGB color value.
I have tried converting into a binary image and searching for the '1' values by using</p><p>BW = im2bw(RGB, level)</p><p>and then [rows,cols] = find(BW==1);</p><p>but I am confused on how to set a level to implement an RGB value so that only my specific color pixels will show up as white in the binary image.</p><p>Is there a better way to find the coordinates of pixels only by using RGB value?</p><p>thanks!</p>Aa Mhttps://kr.mathworks.com/matlabcentral/profile/authors/10264504-aa-mtag:kr.mathworks.com,2005:Question/655272013-03-01T21:54:40Z2018-01-22T22:55:36Zmultiplication table in matlab<p>I want to make the multiplication table using matlab ?</p>mohamedhttps://kr.mathworks.com/matlabcentral/profile/authors/4103440-mohamedtag:kr.mathworks.com,2005:Question/3784442018-01-22T22:42:55Z2018-01-22T22:42:55ZHow can i fix an overlapping yticklabel in a subplot_tight graph?<p>I have a problem with the following code that outputs my graph perfectly however keeps the yticklablel of the axis from -30 to 30. All I want to do is keep this invisible when the user manually wants to change the graph axis. The choice function is used to change the axis to the user's preference, however the default axis I want to keep showing unless changed is -30 to 30. Thanks in advance for the help!</p><pre> if choice == 1
subplot_tight(6,3,14,[0.04 0.04]);
plotavsd_TD(x,AF_ave,AF_SD);
hold on
plotavsd_Right(x,MEAN.(COND_DATE).Ankle_Flexion_Profile_R,SD.(COND_DATE).Ankle_Flexion_Profile_R);
hold on
plotavsd_Left(x,MEAN.(COND_DATE).Ankle_Flexion_Profile_L,SD.(COND_DATE).Ankle_Flexion_Profile_L);
axis([1 100 -30 30]);
line([0 100],[0 0], 'Color', 'black');
line([MEAN.(COND_DATE).Stance_Time_L*100 MEAN.(COND_DATE).Stance_Time_L*100],[-1000 1000], 'Color', 'red');
line([MEAN.(COND_DATE).Stance_Time_R*100 MEAN.(COND_DATE).Stance_Time_R*100],[-1000 1000], 'Color', 'green');
grid on
grid minor
set(gca,'Ylim',[min,max]);
set(gca,'FontSize',8);
y = ylabel('Plan/Dors','FontSize',8.5);
set(y, 'Units', 'Normalized', 'Position', [-0.0625, 0.5, 0]);
set(gca,'xticklabel',{[]});</pre>Vasu Lakkojuhttps://kr.mathworks.com/matlabcentral/profile/authors/6706839-vasu-lakkojutag:kr.mathworks.com,2005:Question/3784432018-01-22T22:39:21Z2018-01-22T22:39:21ZCan gamultiobj deal with unfeasible non linear constraints?<p>I am running an optimization with gamultiobj with non-linear constraints applied. The optimization is related to engine performance and preliminary design. The program involves external program (for the thermodynamics of the engine) and internal matlab functions callings (for the preliminary engine component design). During the optimization, it is possible that few population elements lead to a not feasible design. In addition, the external program might not find a thermodynamic solution. These cases can affect both: the objective function and the constraints function used in gamultiobj.</p><p>If i was using fmincon, for example, in such cases I would return Nan to the system optimizer and fmincon is able to deal with this, generating new design variables. In gamultiobj, however, this is not possible. If I don't put constrains, I can return Inf for the failed objective function evaluation, forcing the GA algorithm to discard that particular point of the current population. If I add constraints, the trick with the objective function still works, however, if the constraints cannot be evaluated, I can't return Nan or Inf to the optimizer (because matlab gives me an error saying that the constraint function output must be real).</p><p>I tried to return high values instead or zeroes, because normally the algorithm evaluates constraints and objective function in series (and the objective output can be Inf), but for some reasons the code keeps evaluating the constraints with different points of the population and does not return to evaluate the objective.</p><p>Have you ever encounter this problem? Do you have any explanation or any intelligent way to set constraints values in case of unfeasible constraint definition?
Thank you very much,
Jacopo</p>jacopo tacconihttps://kr.mathworks.com/matlabcentral/profile/authors/7059527-jacopo-tacconitag:kr.mathworks.com,2005:Question/3270262017-02-26T23:53:49Z2018-01-22T22:37:08ZHow to join or merge two Image Data Stores?<p>If I have two image datastores and I wish to concatenate them. How can I do that?</p><p>Thanks</p>kowshik Thopallihttps://kr.mathworks.com/matlabcentral/profile/authors/7486572-kowshik-thopallitag:kr.mathworks.com,2005:Question/3629642017-10-24T13:11:13Z2018-01-22T22:34:49ZPossibility of decompiling .exe to m files?<p>Hello !!!</p><p>I lost the data of my computer but I have an executable, is it possible to recover the .m files from and executable version ?? using MATLAB?? please it is urgent.</p>Diana Carrero Pintohttps://kr.mathworks.com/matlabcentral/profile/authors/9542862-diana-carrero-pintotag:kr.mathworks.com,2005:Question/3194192017-01-07T15:04:58Z2018-01-22T22:28:27ZHow to extract image region within boundary<p>Hi,
I have to segment the LV from cardiac MRI. The output is an image with a boundary for the specified region (attached image).
My question is how can i get only the region within the boundary. how to set the inside of the boundary to 1 and 0 for the rest for a binary image.</p><p>Thanks in advance.</p><img src = "/matlabcentral/answers/uploaded_files/67007/Capture.PNG">Ynnehttps://kr.mathworks.com/matlabcentral/profile/authors/2961706-ynnetag:kr.mathworks.com,2005:Question/3784302018-01-22T20:56:16Z2018-01-22T22:28:12ZConvert a matrix char to uitable<p>Currently i have a 10x90 matrix, which consist basically of char/text in the following way</p><pre> a = strcat('text', num2str(matrix(:,1)), 'text');</pre><p>Anyone know a easier way for me to export it into a uitable of 10x1?</p><p>I cant export it directly since it isnt a numerical, logical or cell array. Making it a cell array by adding {} also doesnt work, since it became a 1x1.
Also, i tryed to make a loop to convert the variable <b>a</b> into another one line by line, but the matlab gave me the following error: Subscript indices must either be real positive integers or logicals.</p><p>Sorry for the question, i'm new into matlab and programming.</p>Victor Dalostohttps://kr.mathworks.com/matlabcentral/profile/authors/8507625-victor-dalostotag:kr.mathworks.com,2005:Question/3784322018-01-22T21:06:55Z2018-01-22T22:26:40ZWait until dos command is done<p>Hello, my problem is that I need to wait until a DOS-run executable is finished before moving on in my script. Is there a way that Matlab can recognize a DOS window closing? I know the dos() command has a status output, but it says successful in running the .exe not successful in finishing.</p><p>Is there a way to wait for a message from the system saying hey the DOS window has closed?</p><p>I've seen clunky methods work like pause 5 seconds and look for output and loop, but I would think that there is a more direct way to have information passed.</p><p>Thanks!</p>Ryanhttps://kr.mathworks.com/matlabcentral/profile/authors/4305107-ryantag:kr.mathworks.com,2005:Question/3784342018-01-22T21:20:05Z2018-01-22T22:23:26ZHow to put quotes around new vector in each iteration? <p>Suppose this is a vector... [1,1,1,2,1,2] and how to put the single quote around the vector like this...'[1,1,1,2,1,2]'...and then this quoted vector will be placed inside the cell ?</p><p>Final output will be like this...</p><pre class="language-matlab">dict = {'[1,1,1,2,1,2]','[1,1,2,2,1,2]','[1,2,1,2,1,2]'}
</pre><p>then I want to compare using ismember function...</p><pre class="language-matlab">if ismember('[1,1,1,2,1,2]',dict)
</pre><p>Please suggest solution if this is possible in Matlab</p>PUNEET DHEERhttps://kr.mathworks.com/matlabcentral/profile/authors/6448717-puneet-dheertag:kr.mathworks.com,2005:Question/3770812018-01-14T15:12:20Z2018-01-22T22:22:30ZHow can I create semicircle signal in Simulink?<p>Hi, can I create this signal with signal builder in simulink please?</p><img src = "/matlabcentral/answers/uploaded_files/101184/1.jpg"><p>Or should I use some other block or other way how to create this signal?</p><p>Thank you for your help.</p>Jakub Fourhttps://kr.mathworks.com/matlabcentral/profile/authors/11921452-jakub-fourtag:kr.mathworks.com,2005:Question/3784172018-01-22T18:45:44Z2018-01-22T22:17:40Zhow can I fix compiles errors?<p>Dear All, I prepared a GUI file and I want to compile it to make it as an executable file, now after I run it it doesn't work, it keeps giving me the message: exceeds matrix dimension, what is wrong here? I mean the code works, the GUI file works, everything is OK but the exe file does not work !</p>MAHMOUD ALZIOUDhttps://kr.mathworks.com/matlabcentral/profile/authors/8908523-mahmoud-alzioudtag:kr.mathworks.com,2005:Question/3784402018-01-22T22:05:55Z2018-01-22T22:08:40ZGTX1060 for deep learning semantic image segmentation<p>Hello!</p><p>I am attempting to train SegNet for semantic segmentation following the example set here:
https://www.mathworks.com/examples/matlab/community/24778-semantic-segmentation-using-deep-learning</p><p>However, I continue to run into an out of memory error. I am wondering if the error is in my code, or if my GTX1060 3gb GPU is simply not powerful enough to train SegNet as in the example. I have already reduced the mini-batch size to 1, so I'm unsure if there are any other fixes I can make.</p><p>Thanks!</p>TopologicalSpherehttps://kr.mathworks.com/matlabcentral/profile/authors/7542040-topologicalspheretag:kr.mathworks.com,2005:Question/3780372018-01-19T20:40:05Z2018-01-22T22:00:47ZHow can I combine fields for two different structures in two different .mat files?<p>Hello,
I am trying to combine two structures saved in two different .mat files into one structure/.mat file.
I would like to end up with a new 1x1 structure containing the same fields and all the values within the fields for both original files.</p><p>My two files contain the same six fields (x, y, z, a, b, c) containing either cell or double (x,y,z are cell and a,b,c are double) with different dimensions.</p><p>I think I need to combine the fields and then create another structure from them, but I cannot figure out how to do this.</p><p>I think I may need to combine some vertically and some horizontally (1 x value vs. value x 1 dimension), which may be an issue.</p><p>Appreciate any help
Thank you,
Megan</p>Megan Laddshttps://kr.mathworks.com/matlabcentral/profile/authors/9779307-megan-laddstag:kr.mathworks.com,2005:Question/3784162018-01-22T18:35:17Z2018-01-22T21:52:38ZCompute Histogram of an image using loops<p>I'm trying to computer a histogram of an image by using loops. I cannot use the imhist function. How do I do this?</p>Davidson Bockhttps://kr.mathworks.com/matlabcentral/profile/authors/11871670-davidson-bocktag:kr.mathworks.com,2005:Question/3784392018-01-22T21:52:21Z2018-01-22T21:52:21Zcustom color trendline and appropriate legend<p>Hello! I am having trouble getting my trend line to match my marker colors (which are colors from our template) as the way I tried to enter the custom color was not working for me so for now I have gone back to just r and b so it shows.</p><p>Also, I would like to have my legend show either the marker or the trendline, but not have all 4 and I haven't figured out how to do that yet.</p><p>Here is what I'm working with so far:</p><pre class="language-matlab">% sample data
PD = [10.7 7.7 8.3 15.7 8.7 11.3 16.0 12.0 15.3 12.3 10.7 15.0 16.7 11.3];
EKDF = [36.5 41.0 35.5 42.5 44.5 37.0 19.5 41.0 32.0 40.0 43.0 37.0 31.5 36.5];
FKDF = [55.0 52.0 43.0 46.0 46.5 49.0 20.5 46.0 36.0 45.0 49.0 41.5 41.5 38.5];
</pre><pre class="language-matlab">hold on
x1 = EKDF;
y = PD;
sz = 40;
scatter(x1,y,sz,'MarkerEdgeColor',[.5 0 .16],...
'MarkerFaceColor',[.5 0 .16],...
'LineWidth',1.5)
legend('EKDF')
daspect([1 1 1])
coef_fit = polyfit(x1,y,1);
y_fit = polyval(coef_fit,xlim);
plot(xlim,y_fit,'r')
</pre><pre class="language-matlab">x2 = FKDF;
y = PelvDrop;
scatter(x2,y,sz,'MarkerEdgeColor',[0 .4 .6],...
'MarkerFaceColor',[0 .4 .6],...
'LineWidth',1.5)
legend('FKDF')
coef_fit = polyfit(x2,y,1);
y_fit = polyval(coef_fit,xlim);
plot(xlim,y_fit,'b')
</pre>monarchhttps://kr.mathworks.com/matlabcentral/profile/authors/10373831-monarchtag:kr.mathworks.com,2005:Question/3784382018-01-22T21:46:14Z2018-01-22T21:46:14ZCan't find Biovoice analysis tool<p>Hello every one,</p><p>I have read about Biovoice analysis tool that was developed under matlab.
But I couldn't find any information about how to download it and use it. Has anyone used it to answer my question?</p><p>Great thanks</p>Shaya shttps://kr.mathworks.com/matlabcentral/profile/authors/10586872-shaya-stag:kr.mathworks.com,2005:Question/3782632018-01-22T04:49:28Z2018-01-22T21:41:30Zmark points on graph<p>~do calculations</p><p>x=ddata;</p><p>y = edata;</p><p>handles=guidata(hObject);</p><p>[X,Y] = peaks;</p><p>surf(X,Y);</p><p>xlim([-inf inf]);</p><p>ylim([0 inf]);</p><p>plot(x,y,'parent',handles.axes1);</p><p>hold on</p><p>plot(x_mark,y_mark,'c*',handles.axes1)</p><p>hold off</p><p>the x_mark and y_mark are both in array that I got from a while loop.
I made a GUI that plots the figure</p>hi heyhttps://kr.mathworks.com/matlabcentral/profile/authors/10452425-hi-heytag:kr.mathworks.com,2005:Question/3740572017-12-21T11:53:20Z2018-01-22T21:36:50ZTriggering video stream with AND gate.<p>I would like to trigger live video stream with the use of AND gate in Simulink. I used 'from video device' block followed by enabled trigger, which is getting control signal from AND gate and obtaining it's display on video device block. The problem is, it is not generating HDL code for enabled subsystem, triggered subsystem and reset. Please suggest another block which can replace enabled subsystem. So that i can generate HDL code.</p><img src = "/matlabcentral/answers/uploaded_files/99222/1.jpg">ketan zamrehttps://kr.mathworks.com/matlabcentral/profile/authors/7229382-ketan-zamretag:kr.mathworks.com,2005:Question/1170512014-02-21T07:45:27Z2018-01-22T21:35:58ZHow to delete my account?<p>Hi,
I want to delete my account and i already emailed costumers service and they don't seem to want to delete it. I need to use this specific email to create another account because i created this account for student use but i need it for academic use so i can use my universities activation key. I tried asking if they could change me from student use to academic use but it didn't work. All i need is to delete this account and create a new one that's all i want. Can someone please help.</p>Jenniferhttps://kr.mathworks.com/matlabcentral/profile/authors/5082693-jennifertag:kr.mathworks.com,2005:Question/3784372018-01-22T21:30:56Z2018-01-22T21:35:31ZUsing flipud Function?<p>Hi Everybody,</p><p>I am trying to save images but the outputs images were overturned (up down and down up). Therefor I used flipud but it isn't work.</p><p>Thank you in advance</p><p>Reyadh</p><pre class="language-matlab">if true
cd C:\Calculated_NDVI_Arcgis
dinfo = dir('*_B3*.tif');
nfile = length(dinfo);
filenames = {dinfo.name};
for K = 1 : nfile
b3_file{K} = filenames{K};
band_pos{K} = strfind(b3_file{K}, '_B3');
b4_file{K} = b3_file{K}; b4_file{K}(band_pos{K} + 2) = '4';
b3_data{K} = double( imread(b3_file{K}) );
b4_data{K} = double( imread(b4_file{K}) );
finalndvi{K} = (b4_data{K} - b3_data{K}) ./ (b4_data{K} + b3_data{K});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
R = georasterref('RasterSize',size(finalndvi{K}),'LatitudeLimits',[30.95115,31.76385],'LongitudeLimits',[46.58315,47.43285]);
R= flipud(R);
geotiffwrite(sprintf('%d.tif',K),finalndvi{K},R);
end
</pre>Reyadh Albarakathttps://kr.mathworks.com/matlabcentral/profile/authors/8617663-reyadh-albarakattag:kr.mathworks.com,2005:Question/3783992018-01-22T17:18:14Z2018-01-22T21:34:52Zbitsrl of a hex value<p>I want to bit right shift logical a hex value.</p><p>AF is input hex .Then bit is 10101111 . So bitsrl by 2 should give 101011. So out hex 2B.</p><p>I tried converting to dec and binary.But,not getting correct answer.</p><p>When converted k0=k0(:) and bit shifted ,I get both A and F shifted by 2.</p>Adarsh Santhoshhttps://kr.mathworks.com/matlabcentral/profile/authors/11755692-adarsh-santhoshtag:kr.mathworks.com,2005:Question/3782572018-01-22T03:46:15Z2018-01-22T21:33:44ZHow to Compare two arrays with timestamps/datetime using one timestamp/datetime as reference and merge them into one<p>I have a 2-column cell array of elevation data like so:</p><img src = "/matlabcentral/answers/uploaded_files/101984/Elevation%20data.PNG"><p>The date time in this array is in the format: m/d/yyyy hh: mm . The length/number of rows of elevation data is 9537. Assume seconds (secs) values of the date time are zero.</p><p>I have another 2-column cell array of rain data like so:</p><img src = "/matlabcentral/answers/uploaded_files/101982/rain%20data%201.PNG"><img src = "/matlabcentral/answers/uploaded_files/101983/rain%20data%202.PNG"><p>The date time in this array is in the format: dd-mmm-yyyy hh:mm:ss .The length/number of rows of the rain data is 527040.</p><p>I want to have an array of data like the table below
Using the elevation data timestamp as reference, I would like to insert the rain data equivalent into the third column like so. I have done the first 10 values manually:</p><img src = "/matlabcentral/answers/uploaded_files/101985/new%20table.PNG"><p>Coincidentally, from the above table, the raindata is 0 for the first 10 elevation angles but varies further down the line.
The code should ignore the seconds (secs) values in the rain data since they are zero anyways. While the rain datetime is steadily increasing in steps of 1minute (60secs), the elevation data on the other hand, although still in steps of 1minute has some data missing in between, hence inconsistent data. However, for every elevation data value there is a corresponding rain data value.</p><p>I have written this code but it is not working. I am not so familiar with for loops and IF statements. Is there a way to do this without using for loops or IF statements. Could you point me in the direction as to where I can find answers to this problem or kindly, solve this?</p><pre class="language-matlab">For 1=1:length(elevation);
if elevation==find(t==elevation(i,1));
raindata = t(elevation,2);
elevation(i,3) = rain data;
end
continue
end
</pre>Berry236https://kr.mathworks.com/matlabcentral/profile/authors/11981793-berry236tag:kr.mathworks.com,2005:Question/1607852014-10-31T08:30:17Z2018-01-22T21:25:19ZTunable sample time in code generated with PLC coder<p>How can we have a simulink model sample time as a tunable parameter in the code generated with Simulink PLC coder ?</p>Micaëlhttps://kr.mathworks.com/matlabcentral/profile/authors/4501536-micaeltag:kr.mathworks.com,2005:Question/3784352018-01-22T21:23:40Z2018-01-22T21:24:18Zoptimproblem object: Change variable bounds<p>"OptimizationProblem property 'Variables' is read-only". That is the message I get after trying to change something like:</p><pre class="language-matlab">prob.Variables.x.LowerBound = lb
</pre><p>where <tt>prob</tt> is an optimproblem object.</p><p>How can I get around this? Another issue I found was that I could not add variables to the problem, for the same reason. I got around this by adding dummy constraints with all zero coefficients. Overall I like this new tool, it is very convenient, but there should be a way to manipulate variables easily. I am using 2017b.</p>Opt Userhttps://kr.mathworks.com/matlabcentral/profile/authors/4527506-opt-usertag:kr.mathworks.com,2005:Question/3784332018-01-22T21:15:12Z2018-01-22T21:15:12ZImport elements of an array from workspace<p>Hi,
I've created this model in Simulink to import elements of an array of waypoints (x,y) from workspace on a sequential basis so that a Robot can follow them, point after point.</p><img src = "/matlabcentral/answers/uploaded_files/102106/ce338024-7b98-49f3-9bf1-1c80cddc7d84_1.487fb8314852a502ff3b8fb2aa58947c.png"><p>The index selectors switch to the next index by increasing the data store memory variable "A" by "1" when the Robot reaches the current waypoint within 100 m.</p><p>When I run the model the variable "A" jumps to the final value (16 in this case) at the first sample time of simulation. why? any help?</p><p>Below is the matlab function block:</p><pre class="language-matlab">function y = fcn(u,n)
</pre><pre class="language-matlab">global A;
</pre><pre class="language-matlab">if u<100 && A<n
A = A+1;
end
if A>n
A=n;
end
y = A;
end
</pre>Islam Elnadyhttps://kr.mathworks.com/matlabcentral/profile/authors/7481436-islam-elnadytag:kr.mathworks.com,2005:Question/3783972018-01-22T17:10:42Z2018-01-22T22:24:21Zevalin does not work in GUIDE but works flawless while using F5 from the script<p>Hello All,</p><p>I have a .m file where I get a csv file through uigetfile and run through the data and plot some details into an excel file.
While running it from command window or directly from the script the code works perfectly. I copied the same code into a callback of a push button and seems to be stuck in evalin command..</p><pre class="language-matlab">ReportFinal = num2cell(nan(2,2))
FileName = evalin('base','csvfilename');
CO2_GramsPerMile =evalin('base','CO2_grams_per_mile');
</pre><p>even if I was to comment out the 2nd line, the third line pops up as an error.</p><p>the error is as below,</p><pre class="language-matlab">Error using evalin
Undefined function or variable 'CO2_grams_per_mile'.
</pre><pre class="language-matlab">Error in Ver1_GUI_Welcome_2017Jan22_Ver01>pushbutton1_Callback (line 210)
CO2_GramsPerMile =evalin('base','CO2_grams_per_mile');
</pre><pre class="language-matlab">Error in gui_mainfcn (line 95)
feval(varargin{:});
</pre><pre class="language-matlab">Error in Ver1_GUI_Welcome_2017Jan22_Ver01 (line 42)
gui_mainfcn(gui_State, varargin{:});
</pre><pre class="language-matlab">Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Ver1_GUI_Welcome_2017Jan22_Ver01('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
</pre><pre class="language-matlab">Error while evaluating UIControl Callback
</pre><p>the csvfilename variable is obtained with the code</p><pre> [csvfilename, csvpathname] = uigetfile({'*.csv';'*.xls';'*.xlsx';'*.dat'},'File Selector');</pre><p>is there anything wrong in the way I am calling evalin ? or is this a Matlab thingy?</p><p>Any help would be appreciated..</p>Sarathnandanhttps://kr.mathworks.com/matlabcentral/profile/authors/1652958-sarathnandantag:kr.mathworks.com,2005:Question/727982013-04-19T16:38:18Z2018-01-22T21:07:12ZAre accumarray/cellfun/arrayfun/etc multithreaded?<p>As per the subject line, anyone know? If not, could this be done by TMW without a lot of effort?</p>Eric Sampsonhttps://kr.mathworks.com/matlabcentral/profile/authors/3865886-eric-sampsontag:kr.mathworks.com,2005:Question/98222011-06-19T10:20:08Z2018-01-22T21:04:13ZPhotovoltaic MPPT fuzzy logic in Matlab/Simulink<p>A very good day to all of you.</p><p>I am currently simulating a boost converter circuit where the duty cycle is being controlled by a fuzzy logic controller.
Now, the fuzzy logic controller inputs are my Power and Current.</p><p>From what i have known, the inputs are actually a function which denotes as: change of P = P(n) - P(n-1).</p><p>My question is, how to implement this on Simulink block diagram?</p>Jason Leehttps://kr.mathworks.com/matlabcentral/profile/authors/2920827-jason-leetag:kr.mathworks.com,2005:Question/3767552018-01-11T19:57:26Z2018-01-22T21:03:53Zrunning matlab function multiple times from windows command line<p>My matlab code is heavy in terms of memory and cpu cycles and takes days to finish. I need to re-run the code for 10 times. I am doing that using a matlab script, but the machine crashes due to out of memory error. Matlab help documentation recommends for such type of codes to save the work space and restart matlab frequently to avoid memory fragmentation. Therefore, I created the following simple windows script to automate restarting matlab:</p><pre class="language-matlab">@echo off
for /l %%x in (1, 1, 10) do (
matlab -nodisplay -nojvm -nosplash -nodesktop -r "Matlab_function(,);exit"
timeout 30 >nul
)
pause
</pre><p>It seems to me that still multiple instances of matlab are running together. My question is how to ensure that the next call to the matlab function do not happen until the current call is completely finished and the matlab command window is closed? any idea?</p>Mustafa Al-tekreetihttps://kr.mathworks.com/matlabcentral/profile/authors/4580195-mustafa-al-tekreetitag:kr.mathworks.com,2005:Question/3784312018-01-22T21:02:49Z2018-01-22T21:02:49ZChange the input number of channels in Deep learning<p>Is it possible to change the input channel number of a deep learning network to any arbitrary number instead of just 1 or 3? (e.g ImageInputLayer only allows 1 or 3 channels)</p><p>I am doing a research where my task is to classify bunch of 6 dimensional matrixes. So the input for me is a m*n*6 matrix for each sample</p>Rui Xianghttps://kr.mathworks.com/matlabcentral/profile/authors/8412799-rui-xiang