https://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-06-22T17:21:16Ztag:www.mathworks.com,2005:Question/960052012-02-27T22:41:00Z2018-06-22T17:21:16ZWhy do I get the error "Undefined function or variable"?<p>I am receiving the following error message, how can I resolve this issue?</p><pre class="error"> ??? Undefined function or variable ‹FunctionName›
??? Undefined function or method ‹FunctionName› for input arguments of type ‹ClassName›.</pre>MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/4069592018-06-22T14:36:06Z2018-06-22T17:19:33ZI need help plss<p>Hey, i have a problem with this one: Write a function called light_speed that takes as input a row vector of distances in kilometers and returns two row vectors of the same length. Each element of the first output argument is the time in minutes that light would take to travel the distance specified by the corresponding element of the input vector. To check your math, it takes a little more than 8 minutes for sunlight to reach Earth which is 150 million kilometers away. The second output contains the input distances converted to miles. Assume that the speed of light is 300,000 km/s and that one mile equals 1.609 km.
and here's my answer:</p><pre class="language-matlab">function[TimeInMinutes,DistanceInMiles] =light_speed(DistanceInKm)
DistanceInKm=DistanceInKm(:);
TimeInMinutes=sum(DistanceInKm./((3e5)*60));
DistanceInMiles=(DistanceInKm./1.609);
end
</pre>ahmed yassinehttps://www.mathworks.com/matlabcentral/profile/authors/12978562-ahmed-yassinetag:www.mathworks.com,2005:Question/4068152018-06-21T16:38:26Z2018-06-22T17:18:12Zsparse2 mexFunction not found<p>After reading <a href = "https://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/#12">Creating Sparse Finite-Element Matrices in MATLAB</a></p><p>I downloaded sparse2.m form <a href = "http://faculty.cse.tamu.edu/davis/suitesparse.html">SuiteSparse</a> .</p><p>But when I use</p><pre class="language-matlab">D = sparse2(i,j,s);
</pre><p>It shows error</p><pre class="language-matlab">Error using sparse2 (line 27)
sparse2 mexFunction not found
</pre><p>Where can 'sparse2 mexFunction' be founded?</p>JAI PRAKASHhttps://www.mathworks.com/matlabcentral/profile/authors/7172030-jai-prakashtag:www.mathworks.com,2005:Question/4053812018-06-13T01:53:28Z2018-06-22T17:17:47Zhow to solve transcedental equation in matlab<p>I am practicing solving the next transcendental equation in matlab</p><pre class="language-matlab">(a/c)*sqrt((b*m1)^2-(p*c)^2)-atan( sqrt(( (p*c)^2-(b*m2)^2 ) /( (b*m1)^2-(p*c)^2 ) ) )-atan( sqrt(( (p*c)^2-(b*m3)^2 ) /( (b*m1)^2-(p*c)^2 ) ) ) == r*pi
</pre><p>here</p><pre class="language-matlab">a=1x10^-6;
c= 3x10^8;
m1=2.2;
m2=1.5;
m3=1;
</pre><p>I was trying to plot "p" vs "b" where "b" runs from 0 to 3x10^15 and r is a parameter that takes values of 0, 1 and 2. I already tried all day but I cannot find solution, I tried with fzero(fun,xo) without success, can you give any suggestion?</p>alburary danielhttps://www.mathworks.com/matlabcentral/profile/authors/12996088-alburary-danieltag:www.mathworks.com,2005:Question/4066472018-06-20T19:37:14Z2018-06-22T17:13:38ZOpen fig file from an old version (2009) in 2015 version<p>I have some fig files I saved using Matlab 2009. Now I'm trying to open these files in Matlab 2015 but the figures are blanked. The Axis are correct, the labels are correct and also the colorbar are OK, but evething inside is blanked. How can I open these figures?</p><p><b>EDIT: Cassiano Bortolozo's "Answer" moved here:</b></p><p>Certainly Attached are the figures, the .png figure is how the .fig should be.</p>Cassiano Bortolozohttps://www.mathworks.com/matlabcentral/profile/authors/8329212-cassiano-bortolozotag:www.mathworks.com,2005:Question/4069612018-06-22T14:37:29Z2018-06-22T17:13:29ZHow can i convert diameter of irregular object in pixel to mm, without drawing line again and again.. also i am not avaliable with the true height of the image in mm...???<pre> conversion from pixels to mm</pre>Savy Gulatihttps://www.mathworks.com/matlabcentral/profile/authors/12422030-savy-gulatitag:www.mathworks.com,2005:Question/4068442018-06-21T19:59:21Z2018-06-22T17:11:19ZTry to do a curve fitting on a komplex alternating function <img src = "/matlabcentral/answers/uploaded_files/122313/Unbenannt.JPG"><p>Dear community members,</p><p>i try to do a curve fitting on this komplex function. I wasn't successful with "polyfit" and "ezyfit". Is there any possibility?</p><p>Thanks for your help!
Max</p>Max Weberhttps://www.mathworks.com/matlabcentral/profile/authors/11855743-max-webertag:www.mathworks.com,2005:Question/4069702018-06-22T15:28:51Z2018-06-22T17:11:11ZCreating separate instances of a custom GUIDE figure and access ui elements inside<p>I created a custom figure with GUIDE that I want to create multiple instances of. Each custom figure contains 3 sliders and a set of axes. I want to treat that custom figure as an object and then fig1 = new customFigure() fig2 = new customFigure() etc. I also want to be able to access the child components inside each custom figure so for example I want to be able to read fig2.slider1.Value from my main program file and have that be a different instance than fig1.slider1.Value. (As an aside, my background is C and Java so I don't fully understand how MatLab is working here)</p>Timothy Masthttps://www.mathworks.com/matlabcentral/profile/authors/12930837-timothy-masttag:www.mathworks.com,2005:Question/3043932016-09-25T06:50:34Z2018-06-22T17:08:41ZHow can I play video in MATLAB GUI after browsing the video?<p>I have created the following GUI in MATLAB. I want to browse the video and display the path of video in the edit textbox besides the browse button. And after clicking the "Play" button, it should play the browsed video in the static text box. Please help me with the code.
Following is the GUI:</p><img src = "/matlabcentral/answers/uploaded_files/59888/play_video.png">Isha Pandyahttps://www.mathworks.com/matlabcentral/profile/authors/8725391-isha-pandyatag:www.mathworks.com,2005:Question/4069852018-06-22T17:00:10Z2018-06-22T17:00:10ZPop_loadbv error while opening .vhdr files on eeglab<p>I am using eeglab on the matlab and when I open a .vhdr file on eeglab, i get an error 'pop_loadbv() on line 179-- no file or directory found' but when I use it to open a .vhdr file in another folder, it works. I have added the folder to the path numerous times. I have also moved the folder and then added it to the path to make sure it was more accessible. Can anyone help me out with this?</p>Nupur Davehttps://www.mathworks.com/matlabcentral/profile/authors/10676820-nupur-davetag:www.mathworks.com,2005:Question/4069792018-06-22T16:22:22Z2018-06-22T16:57:07ZHow to convert char data to num??<p>I have .mat file which contains labels of my image dataset. These labels are numbers (0,1,2,3,4,5,6) but in mat file these are saved as characters ('0','1','2','3','4','5','6'). How to convert these chars to num??</p><pre> % Features Extraction of Face based on HOG
clear;
testing=imageSet('Testing\','recursive'); % folder name of the database </pre><pre class="language-matlab">K=1;
</pre><pre class="language-matlab">for i=1:size(testing,2 )
for j=1:testing(i).Count
Face=read(testing(i),j);
Face=imresize(Face, [48 48]);
HOG_Features=extractHOGFeatures(Face);
testingFeatures(K,:)=single(HOG_Features);
testinglabel{K}=testing(i).Description;
K=K+1;
end
persons{i}=testing(i).Description;
end
testinglabel=testinglabel';
csvwrite(' Testing.csv', testingFeatures)
</pre>saeeda saherhttps://www.mathworks.com/matlabcentral/profile/authors/7737318-saeeda-sahertag:www.mathworks.com,2005:Question/4069842018-06-22T16:57:06Z2018-06-22T16:57:06ZMap of Trees For Classification Models<p>For the models created using the Classification Learner App, is it possible to see a map of the decision trees and how many samples are split to each branch?</p>John Hardyhttps://www.mathworks.com/matlabcentral/profile/authors/13056804-john-hardytag:www.mathworks.com,2005:Question/4069832018-06-22T16:55:25Z2018-06-22T16:55:25ZMesh export fem simulation<p>Hi,</p><p>I have a question about mesh export.
Let's suppose I have a code that generates matrices of 1D, 2D, 3D finite elements and the nodes table ID x y z of the nodes.
If I need to simulate the mechanical behaviour using this mesh, there is a way to use it e.g. in Nastran/Patran et simila?</p><p>Thank you for your attention</p>mark heimlichhttps://www.mathworks.com/matlabcentral/profile/authors/8048818-mark-heimlichtag:www.mathworks.com,2005:Question/4068752018-06-22T00:40:29Z2018-06-22T16:54:13Zspeed-up the given code<p>The following code is taking a most of the time in my script and I have to run the script many times Is there a way to reduce the time for its execution.</p><pre class="language-matlab">t=0:200000;
lambda=[1,2,3;4,5,6;7,8,9;10,11,12];
for trans=1:size(lambda,1)
uh_fun{trans}=expconv(lambda(trans,:));
end
</pre><pre class="language-matlab">uh=zeros(length(t),1);
for i=1:length(uh_fun)
temp_uh_fun=uh_fun{i};
f_gamma=zeros(length(t),1);
for j=1:length(temp_uh_fun)
f_gamma=f_gamma+temp_uh_fun{j}(t)'; % this line take a lot of time
end
uh=uh+p(i)*f_gamma; % p is an array of scalars
end
</pre><p>I have added expconv function for reference. I need some suggestions to improve the performance. I have also attached a pdf which contains profiler analysis of anonymous function in expconv.</p>Abhinavhttps://www.mathworks.com/matlabcentral/profile/authors/5297551-abhinavtag:www.mathworks.com,2005:Question/4068612018-06-21T21:24:11Z2018-06-22T16:53:10ZI'm compiling with lcc-win32 2.4.1 on w10 64bit platform in 32bit Matlab, why is my program not working on w7 target machine with compatible MCR?<p>I'm running windows10 on a 64bit platform.</p><p>I downloaded the 32bit v. of R2012a Matlab in order to get the included lcc-win32 2.4.1 compiler.</p><p>From this question thread, <a href = "https://www.mathworks.com/matlabcentral/answers/143754-64-bit-32-bit-compatible-standalone-app">https://www.mathworks.com/matlabcentral/answers/143754-64-bit-32-bit-compatible-standalone-app</a></p><p>I have reason to believe that my compiled programs will be compatible with 32 and 64bit target systems, provided they have the necessary MCRs.</p><p>My target system is windows7, 64bit, with the R2012a MCRs for 32 and 64bit installed.</p><p>I attached a photo of the problem details, when the .exe stops working...</p><p>BONUS Question: Will there be any foreseeable issues downloading the MCR for compatibility with newer matlab versions on a windows7 environment? or Rather, is it generally recommended to use matlab versions in the era of w7 when target systems are running w7?</p>Benjamin Hardyhttps://www.mathworks.com/matlabcentral/profile/authors/12178312-benjamin-hardytag:www.mathworks.com,2005:Question/4069822018-06-22T16:50:27Z2018-06-22T16:50:27ZError At "Test" stage under Hardware Implementation for Simulink Coder: Cannot connect to device. 'Check that the device address, username, and password are correct.'<p>I am currently working on controlling a Crazyflie quadrotor using ROS and Simulink and need to create a Standalone node for that.
while following the steps in the mathworks tutorial to create a Standalone node for ROS I get the following error when trying to configure the connection to my ROS device:'Check that the device address, username, and password are correct.'</p><img src = "/matlabcentral/answers/uploaded_files/122420/error.png"><p>I really dont know what might be the real problem since I can actually connect to my ROS device and have access to the topics.</p><img src = "/matlabcentral/answers/uploaded_files/122421/rosinitTopics.png"><p>I can also publish and subscribe messages to the topics using Simulink with no problems (/crazyflie/cmd_vel and /crazyflie/pose in this case). Because of this I tried ignoring this error and went ahead to generate the code by following the next steps in the tutorial: "Code/ C/C++ Code/ deploy to hardware", but in the process I am prompted again for my username, password and device Address and cannot pass this stage. I am using using Ubuntu 16.04 in this computer (no virtual machine) as a ROS device.</p>Rafael Salomon Sanchezhttps://www.mathworks.com/matlabcentral/profile/authors/8998386-rafael-salomon-sancheztag:www.mathworks.com,2005:Question/4069472018-06-22T13:19:26Z2018-06-22T16:47:31Ztable block growth slow<p>Hi,</p><p>I am trying to fill up a table with mixed data containing cashflows. each mortgage gets multiple lines. Preallocation of a similair table does not seem solve this problem. For preallocation i used repmat to create a table as large as the output containing dummy vars. Because dynamic allocation is complexer to read and gave no performance boost I decided to drop this approach.</p><p>The process of dynamically building the table starts out fairly fast but after 35000 iterations, where each adds blocks of about 360 new records, the perfomance decreases very fast. Takes about an hour or more.</p><pre> enddataset = [dataset;newblock] % dynamic, slows over time</pre><p>the tictoc slows down. now the weird stuff it that when I use struct it remains fast (11/12 minutes):</p><pre> myStruct.iterationLabel = newblock. % does not slow over time</pre><p>As I said using repmat and preallocation does not speed up.</p><p>Is it possible to grow a table in a fast manner?</p>Alex Bhttps://www.mathworks.com/matlabcentral/profile/authors/2872347-alex-btag:www.mathworks.com,2005:Question/4069812018-06-22T16:46:53Z2018-06-22T16:46:53ZHow to write a 16 bit image with a drawing rectangle in a folder<p>I am working with a 16 bit DICOM Image whose size is 512*512. I want to draw a rectangle at 250,375 positions with length and width 50,50 respectively. I am capable to draw rectangle on that particular position. But, I am incapable to save the image with the rectangle. Is it possible to write the image with rectangle.</p><p>I=dicomread('F:\img1.dcm');
figure,imshow(X, []);
hold on;
title('16 bit image.', 'FontSize', 10);
rectangle('Position', [250,375,100,100],...
'EdgeColor','r', 'LineWidth', 3);
imwrite(X,'C:\Users\Jhilam\Desktop\code\myfile.png','WriteMode','append');</p>Jhilam Mukherjeehttps://www.mathworks.com/matlabcentral/profile/authors/4795239-jhilam-mukherjeetag:www.mathworks.com,2005:Question/4069802018-06-22T16:45:32Z2018-06-22T16:45:32ZHow to create a loop that creates a set of ARIMA models and estimates the models to give LogL results<p>Hi there,</p><p>I have manually created 16 arima models and have estimated them to produce LogL results in order for me to select the most appropriate model for my data.</p><p>See below for how I have manually created them.</p><pre> mdl20=arima(1,0,1);
mdl21=arima(1,0,2);
mdl22=arima(1,0,3);
mdl23=arima(1,0,4);</pre><pre> % all the way to</pre><pre> mdl32=arima(4,0,1);
mdl33=arima(4,0,2);
mdl34=arima(4,0,3);
mdl35=arima(4,0,4);</pre><p>then I have used this function to estimate them using my dataset L_Ret:</p><pre> [EstMdl20,~,logL20] = estimate(Mdl20,L_Ret);
[EstMdl21,~,logL21] = estimate(Mdl21,L_Ret);
[EstMdl22,~,logL22] = estimate(Mdl22,L_Ret);
[EstMdl23,~,logL23] = estimate(Mdl23,L_Ret);</pre><pre> % all the way to</pre><pre> [EstMdl32,~,logL32] = estimate(Mdl32,L_Ret);
[EstMdl33,~,logL33] = estimate(Mdl33,L_Ret);
[EstMdl34,~,logL34] = estimate(Mdl34,L_Ret);
[EstMdl35,~,logL35] = estimate(Mdl35,L_Ret);</pre><p>Any help will be immensly appreciated</p>harry gallowhttps://www.mathworks.com/matlabcentral/profile/authors/11095796-harry-gallowtag:www.mathworks.com,2005:Question/4056262018-06-14T08:39:08Z2018-06-22T16:38:33ZMATLAB 2018a -MacOS 10.13.5 - Crash on application start<p>I installed MATLAB and SIMULINK for use with the Arduino Engineering Kit on a Mac running 10.13.5.
Installation and activation works perfect.</p><p>If try to start MATLAB_2018a the application crashes imediatly:</p><pre class="language-matlab">Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
</pre><pre class="language-matlab">Application Specific Information:
[753] stack overflow
</pre><p>The system language is set to English, Update 3 is installed and JDK is 8u171</p><p>Does anyone else have this problem, or is this a known issue?</p><p>Thanks,
Christian</p>Christian Eggerhttps://www.mathworks.com/matlabcentral/profile/authors/13016259-christian-eggertag:www.mathworks.com,2005:Question/49832011-04-07T09:43:06Z2018-06-22T16:35:32Zbeautiful GUIs (searching for examples)<p>I'm looking for an example of a beautiful MATLAB GUI that's been customized from the default settings with nicer buttons, colors, possibly transparency, etc. I'm thinking of something more reminiscent of the mac interface rather than the default settings for GUIs.</p>
<p>Do you have any examples, ideally with code?</p>Roberthttps://www.mathworks.com/matlabcentral/profile/authors/301002-roberttag:www.mathworks.com,2005:Question/4069542018-06-22T14:13:37Z2018-06-22T16:27:12ZHow to detect the change point<pre> Hi,
I want to detect the change point for example in the below data:</pre><pre> -32526
-32526
-32526
-32526
-32526
-32526
-32526
-32526
-25123
-25123
-25123
-25123
0.25
12562
32526
32526
32526
12326
-32526
-32526
-32526
-25123
1203
23562
32526
32526</pre><pre class="language-matlab">its a time series data, and one data per sec.
</pre><pre class="language-matlab">I want to detect the change point, but there are small changes like 8 sec, but I want to catch if the change (in %) is >50% within 3~5 seconds. that is like at 12th second.
</pre><pre class="language-matlab">I use the below code, but don't know exactly how to catch what I want.
</pre><pre class="language-matlab">[~,~,data]=xlsread('findPeaksInput.xlsx');
data=cell2mat(data);
diff_data=diff(data);
diff_data=[0;diff_data];
diff_data=abs(diff_data);
</pre><pre class="language-matlab">[row,col]=find(diff_data>0);
</pre><p>kindly some one help, many thanks in advance,</p>Mekala balajihttps://www.mathworks.com/matlabcentral/profile/authors/5786945-mekala-balajitag:www.mathworks.com,2005:Question/4069732018-06-22T15:40:28Z2018-06-22T16:21:33ZHow do I efficiently replace data in data sets where I want to find a value in the data that is in one array and replace it with the data in the same position in another array.<p>For example:
A = (N1, N2, N3..., N20)
B = (NN1, NN2, NN3..., NN20)
C = (Data1, Data2, .... Data13000)</p><p>N1, NN1, and Data1 are all numbers there is not a relationship between them other than I want to look
in C and replace any exact values that can be found in A with the exact values found in the same position in B.
I can do this in for loops but I think there must be a more efficient way than:
for i = 1:length(c)
for j = 1:length (A)
if C(i) == A(j)
C(i) = B(j)
end
end
end</p>Rebecka McSloyhttps://www.mathworks.com/matlabcentral/profile/authors/8040053-rebecka-mcsloytag:www.mathworks.com,2005:Question/4068722018-06-21T23:18:46Z2018-06-22T16:20:18ZIsolating specific dots in an image.<p>Hello, I'm trying to get my image to the point where only the dots inside the black squares remain.</p><p>So far, all I've done with this code is use inmextendedmin on the original grayscale image, and then masked it ontop of the grayscale image to produce this result.</p><pre class="language-matlab">figure(1);
imshow(grayImage);
mask = imextendedmin(grayImage,2);
figure(2);
imshow(mask);
figure(3);
imshowpair(grayImage,mask,'blend');
</pre><p>Before, I had been trying to use watershedding, dividing the background, and a lot of other neat tricks to try and single out the black dots, but it seems that this simple bit of code alone gets me half way to what I want (As each black square has a dot already in it, all i want are those dots). Is there a way to get rid of everything else in this image besides the gray dots inside the black dots?</p><p>The problem I often had with watershedding and whatnot is I needed a variable threshold, as well as watershedding was rather time and processes intensive, so I'm trying to find more efficient ways of doing it.</p>Kimo Kaliphttps://www.mathworks.com/matlabcentral/profile/authors/13013968-kimo-kaliptag:www.mathworks.com,2005:Question/4069752018-06-22T15:49:06Z2018-06-22T16:16:17ZI am doing project on currency recognition. I am not able to identify the object on original image. Please help me<img src = "/matlabcentral/answers/uploaded_files/122422/output.PNG"><p>close all;
clear all;
clc;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;</p><p>%%STEP 1:</p><p>% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Users\Hackerz\Documents\project dataset';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, {'*.jpeg': '*.png' : '*.jpg'});
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
image = imread(fullFileName);
%image=imfilter(image,fspecial('unsharp'));
imshow(image), title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);</p><p>%%STEP 2:
%next step is to crop the image</p><p>% hsvImage = rgb2hsv(image);
% sImage = hsvImage(:, :, 2);
% subplot(2, 3, 2);
% imshow(sImage, []);
% title('Saturation Image', 'FontSize', fontSize, 'Interpreter', 'None');
% subplot(2, 3, 3);
% histogram(sImage);
% grid on;
% title('Histogram of Saturation Image', 'FontSize', fontSize, 'Interpreter', 'None');
% % Threshold.
% %just adjust the threshold value if cropped image is not obtained
% mask = sImage > 0.144;
% % Extract biggest blob.
% % Here 1 shows that we need one object to be shown
% mask = bwareafilt(mask, 2);
% % Fill holes.
% mask = imfill(mask, 'holes');
% subplot(2, 3, 4);
% imshow(mask);
% title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
% % Get bounding box.
% props = regionprops(logical(mask), 'BoundingBox');
% % Crop image.
% croppedImage = imcrop(image, props.BoundingBox);
% subplot(2, 3, 5);
% imshow(croppedImage);
% title('Cropped Image', 'FontSize', fontSize, 'Interpreter', 'None');</p><p>%%STEP 3:</p><p>% i) resizing image
image_resized=imresize(image , [520 680]);
figure, imshow(image_resized);</p><p>% ii) removing any kind of noise
grayimage=rgb2gray(image_resized);
n=imnoise(grayimage,'salt & pepper',0.02);
Kmedian = medfilt2(n);
imshowpair(n,Kmedian,'montage'), title('Noise Removed');</p><p>% iii) adjusting image contrast
image_adjust=imadjust(Kmedian);
figure,imshow(image_adjust);
%% STEP 4:
%cropping region that I need.
image_region=image_adjust(340:500,480:680);
figure, imshow(image_region);
image_adjust=imadjust(image_region);</p><p>%%Step 5:
image_binarize=imbinarize(image_adjust);
figure,imshow(image_binarize);
cann=edge(image_binarize,'canny');
BW2 = bwmorph(cann,'close');
figure,imshow(BW2),title('canny applied');
C=imfill(BW2,'holes');
figure,imshow(C),title('Hole filling');
C = bwareaopen(C,500);
%lableing
label=bwlabel(C);
totalObjects=max(max(label));
im1=(label==1);
figure,imshow(im1);
figure,imshow(label==2);</p><p>%identifying the the objects separately
for j=1:max(max(label))
[row , col]=find(label==j);
len=max(row)-min(row)+2;
width=max(col)-min(col)+2;
target=uint8(zeros([len width] ));
sy=min(col)-1;
sx=min(row)-1;</p><p>for i=1:size(row ,1)
x=row(i,1)-sx;
y=col(i,1)-sy;
target(x,y)=image(row(i,1),col(i,1));
end
mytitle=strcat('Object number',num2str(j));
figure,imshow(target);
title(mytitle);</p><img src = "/matlabcentral/answers/uploaded_files/122414/original_image.jpg"><p><<</p><img src = "/matlabcentral/answers/uploaded_files/122417/5.PNG"><img src = "/matlabcentral/answers/uploaded_files/122416/0.PNG"><p>>></p><p>end</p>Anum Fatimahttps://www.mathworks.com/matlabcentral/profile/authors/12312523-anum-fatimatag:www.mathworks.com,2005:Question/848702013-08-16T07:08:54Z2018-06-22T16:15:02ZHow to divide images into square grid in matlab?<p>Color images divide in sub parts individual but looking like single image to users. it will possible in matlab?</p><p>Basically the image is divided into parts called grids, and each grid will working individual, is this possible?</p>vina borkarhttps://www.mathworks.com/matlabcentral/profile/authors/4197324-vina-borkartag:www.mathworks.com,2005:Question/4069552018-06-22T14:22:42Z2018-06-22T16:13:13ZHow to find the x-coordinate for the maximum value(peak) in a plot?I have an FFT plot for a vibration data of a bridge as shown in the figure.I want to know at which frequency(x-axis) the amplitude(y-axis) is maximum to find critical frequency.<img src = "/matlabcentral/answers/uploaded_files/122405/Screenshot%20(96).png"><pre class="language-matlab">fs=2000;
T=1/fs;
Length='what is the length?';
L=input(Length);
t=(0:L-1)*T;
ACC='which matrix has the acceleration data?';
accdata=input(ACC');
y=fft(accdata);
p2=abs(y/L);
p1=p2(1:L/2+1);
p1(2:end-1)=2*p1(2:end-1);
f=fs*(0:(L/2))/L;
plot(f,p1)
xlabel('frequency(Hz)')
ylabel('Amplitude')
</pre>Karthikeyan Karuppusamyhttps://www.mathworks.com/matlabcentral/profile/authors/10920979-karthikeyan-karuppusamytag:www.mathworks.com,2005:Question/4069782018-06-22T04:00:00Z2018-06-22T16:10:14Zgetframe too slow<p>I am trying to call "getframe" to save an animation from a figure and then using "VideoWriter" to turn it into a video file, but "getframe" is too slow as I am running at 25 frames per second. Is there any way to get around this?</p>MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/4069432018-06-22T13:11:41Z2018-06-22T15:58:43ZHow to make a new matrix from find function results of different size <p>I have a matrix of IC 2008x1 that has values from 1 to 16 (some in between number might be missing) and I want to create a matrix that each column has the rows of the original matrix that correspond to each value 1 to 16
eg original matrix 4; 1; 3; 2; 5; 6; 4;
new matrix [2] [4] [3] [1;7] [5] [6]</p><p>I try to do this like this
for j=1:B</p><pre> k=find(IC==j);
F(:,j)=k;</pre><p>end
where B is 16 but it says that Subscripted assignment dimension mismatch.
Do you know an alternative that works regaldless of this mismatch?</p>Georgios Tertikashttps://www.mathworks.com/matlabcentral/profile/authors/11056216-georgios-tertikastag:www.mathworks.com,2005:Question/4069772018-06-22T15:57:33Z2018-06-22T15:57:33ZWhy does not change the gof (goodness of fit) while changing smoothing parameters?<p>Hi everybody,</p><p>my name is Chris and I have a problem for a few weeks. I couldn´t solve my problem yet.</p><p>I have to say that I work with Matlab for one year.</p><p>I fit a first surface in a pointcloud. Then I smooth the z values of particular parts of my first surface with Gaussian smoothing or median filter to minimize noise. In each of the smoothed parts I fit a second surface.
So my aim is to get a "best-fit"-solution or a result that shows the minimum of fit-errors (sse: sum of squared errors) of the second surfaces.</p><p><b><i>Here is my problem:</i></b></p><p>The parameters of the second fits (gof) stay always the same regardless of changing the smoothing parameters like sigma of Gaussian filter or filterorder and dimension of medianfilter.
I guess the parameters of gof have to change by changing the adjustments of the filters.
But they don´t change anyway.</p><p>So where is the mistake?</p><p>Is the problem that i don´t change the properties of the filters but only the strength of the smoothing (sigma or dimension and filterorder)</p><p>I hope somebody is able to help me or has an idea for a solution.</p><p>Greets,
Chris</p><p>My code:</p><pre> property1 = 'linearinterp';
figure(5);
% 1. FIT
[sf1,gof1,out1] = fit([x1,y1],z1,property1);
plot(sf1, [x1, y1],z1);
view(-3,-72);
xlabel('X in Metern')
ylabel('Y in Metern')
zlabel('Z in Metern')
title('Punktewolke und Hüllfläche')</pre><pre> % Gaussian filter of one surface part
figure(20); % in Metern
Zfiltgauss2 = imgaussfilt(zqneuneu1,sigma);
surf(epsilon1,theta1,Zfiltgauss2);
view(-3,-72);
title('geglättete Hüllfläche (linker winkel) mit Gaußfilterung');
xlabel('X in Metern')
ylabel('Y in Metern')
zlabel('Z in Metern')</pre><pre> % or median filter of one surface part
figure(28);
Zfiltmedian1 = medfilt1(zqneuneu1,mf,[],md,property3,property4);
surf(epsilon1,theta1,Zfiltmedian1);
view(-3,-72);
title('geglättete Hüllfläche (linker Mundwinkel) mit Medianfilterung');
xlabel('X in Metern')
ylabel('Y in Metern')
zlabel('Z in Metern')</pre><pre> % 2. FIT
property5 = 'linearinterp';
property6 = 'cubic';
[Xout1, Yout1, Zout1] = prepareSurfaceData(epsilon1,theta1,Zfiltmedian1); %
[sf4,gof4,out4] = fit([Xout1, Yout1], Zout1,property5);
figure(37); % in Metern
plot(sf4); % Ausgabe 2.Hüllfläche in Metern
view(0,-72);
xlabel('X in Metern')
ylabel('Y in Metern')
zlabel('Z in Metern')
title('2. Hüllfläche linker Mundwinkel')</pre>Christian Auerhttps://www.mathworks.com/matlabcentral/profile/authors/10138450-christian-auertag:www.mathworks.com,2005:Question/4069762018-06-22T04:00:00Z2018-06-22T15:55:05Zsoftware interrupt<p>I am developing a near time system data in the data historian have data feed into a program. It fills up a buffer and when the buffer gets full, I want to be able to know that and act on that and do processing.</p><p>Is there a software interrupt or something that will allow me to do this?</p>MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/4064282018-06-19T19:43:46Z2018-06-22T15:53:40ZCell Image Processing Segmentation/Cell Counting Problem<p>Hi! I am currently looking at cancer squamous carcinoma cells. I am attempting to process and segment the cells so I will be able to count them, but it is difficult for me to segment them because the cells are overlapping and do not have well-defined borders. I have tried turning the picture to black & white using a threshold (im2bw(X, graythresh(X)), but it results in poorly segmented cells that are hardly defined. I would also like to be able to automatically count the cells. Any tips on how to tackle this problem with MATLAB? Below I have attached the original cell image, and my attempt to process it for automated counting. Any help would be greatly appreciated!</p><img src = "/matlabcentral/answers/uploaded_files/122025/spim_TL001_Angle1(originalphase).png"><img src = "/matlabcentral/answers/uploaded_files/122028/Screen%20Shot%202018-06-19%20at%203.56.49%20PM.png">Emma Wonghttps://www.mathworks.com/matlabcentral/profile/authors/12683680-emma-wongtag:www.mathworks.com,2005:Question/4069742018-06-22T15:46:19Z2018-06-22T15:46:19ZHow to input multiple signals into Discrete state space block<p>I am trying to create a state space model, but i am having trouble getting my input set up. All the elements in A,B and C are measured inputs into my model and the will change with each time step. How do i input these into the discrete state space block with only one input?</p>Paul Andersonhttps://www.mathworks.com/matlabcentral/profile/authors/3898995-paul-andersontag:www.mathworks.com,2005:Question/4068832018-06-22T02:32:14Z2018-06-22T15:42:16ZSimulation time in Simulink<p>I need to run a simulation from x sec to y sec in Simulink enviroment. I go to Solver --> set Start time=x Stop Time=y and run simulation. But this doesn´t work because simulation keep starting @ 0 sec. Does anybody knows how to do it?</p>Pablo Pahttps://www.mathworks.com/matlabcentral/profile/authors/10018017-pablo-patag:www.mathworks.com,2005:Question/4069722018-06-22T04:00:00Z2018-06-22T15:40:02Zcone structure<p>I want to have a set of cones at specific positions and have a function that outputs the z-position given the x, y coordinates. If there is no cone at that location, z should return zero, otherwise z should return the height of the cone at that (x,y) position. The cones are defined by their center position, radius and height.</p><p>How can this be done?</p>MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/4068122018-06-21T16:30:13Z2018-06-22T15:37:53ZHow can I open a generic (not defined) EXCEL file ? <p>Hello,</p><p>the procedure to access a spreadsheet data from MATLAB running an Excel application in an Automation server is well known and explained at the matlab documentation. At the Matlab documentation can be seen something like this:</p><p>exl = actxserver('excel.application');</p><p>exlWkbk = exl.Workbooks;</p><p><b>exlFile = exlWkbk.Open([docroot '/techdoc/matlab_external/examples/input_resp_data.xls']);</b></p><p>I am writing a code at GUIDe and I haven't found the code to load a generic excel file at a programm function ( something like winopen(cd) at the Command Window). There are other matlab functions like uiopen('-file'), but they dont load the file. Open does also not work because the file in that case has to be defined by the programmer. I need the file to be choosed by the end user.</p><p>Thank you.</p>Fernandahttps://www.mathworks.com/matlabcentral/profile/authors/12336997-fernandatag:www.mathworks.com,2005:Question/4069522018-06-22T13:53:24Z2018-06-22T15:37:34ZIs there a way to avoid calling a superclass constructor during the execution of a subclass constructor?<p>When executing a superclass constructor, my code executes a subclass constructor. To avoid an infinite loop, I don't want the subclass constructor to execute the superclass constructor in this case. How do I avoid this? In particular, running the player class constructor prompts the user for selecting a file which determines which subclass to load the file as: Pfighter or Pwizard. The subclass, Pfighter, is a subclass of the player and character superclasses. This causes the player constructor to execute which causes an infinite loop due to the fact that the subclass can't pass information about the previous iteration to the superclass during instantiation. Again, not desirable. Can I retype the object to the lower class without rerunning the superclass constructor?</p><p>classdef character < handle</p><pre> % player class hierarchy
% handle
% |
% character
% |
% ------------------------------------------------
% | | | |
% AI wizard fighter player
%
% Cwizard (AI&wizard), Cfighter(AI&fighter), Pwizard (player&wizard), Pfighter(player&fighter)</pre><pre> properties
Name
Class
Level
Team
Marker
HP
MP
MPcost
Speed
Gun
Range
Damage
Spellbook
card
HPmax
status
ID
position
positionold
legend
scatter
outofbounds = false
levelup = false
AIplayer</pre><pre> % AI defined in CWizard, PWizard, CFighter, PFighter
% spells defined in wizard
% XP defined in PWizard, PFighter
% class defined in wizard and fighter
% MPcost defined in wizard
% Spellbook defined in wizard
% MPmax defined in wizard
end</pre><pre> methods</pre><pre> function obj = character(varargin) % obj = character(game,n)
% Help text
%
% player = player(game,n)
%
% game is a game object and n is a player number for the
% player ID
%
if nargin == 0
g = game('settings');
n = 1;
end</pre><pre> obj.status = status();
end</pre><pre> function obj = getcard(obj)
obj.card = card(obj.AIplayer);
fieldnames = fields(obj.card);
for j=1:size(fieldnames,1)
obj.(fieldnames{j}) = obj.card.(fieldnames{j});
end
if obj.AIplayer
if strcmp(obj.Class,'Fighter')
obj = Cfighter(obj);
else
obj = Cwizard(obj);
end
else
if strcmp(obj.Class,'Wizard')
obj = Pwizard(obj);
else
obj = Pfighter(obj);
end
end
%
% Set Starting Positions
%
s = settings;
switch obj.Team
case 'red'
obj.position = [-s.gridsize,-s.gridsize];
case 'green'
obj.position = [s.gridsize,s.gridsize];
case 'blue'
obj.position = [-s.gridsize,s.gridsize];
case 'yellow'
obj.position = [s.gridsize,s.gridsize];
end
if obj.AIplayer
obj.position = obj.position + [3*rand(),3*rand()];
end
obj.positionold = obj.position;
end
end
end</pre><p>classdef player < character</p><pre> % player class hierarchy
% handle
% |
% character
% |
% ------------------------------------------------
% | | | |
% AI wizard fighter player
%
% Cwizard (AI&wizard), Cfighter(AI&fighter), Pwizard (player&wizard), Pfighter(player&fighter)</pre><pre> properties
levels
XP
end</pre><pre> methods
function obj = player(obj)
% Add an XP-to-level table to the player structure to allow for checking
% level-up later in the game.
obj.AIplayer = false;
g = game('settings');
levelsfile = file([g.settings.LevelsPath g.settings.Levelfile],'int');
obj.levels = levelsfile.table;
if ~exist(obj.card)
obj.getcard;
end
obj.getXP;
end</pre><pre> function player = getXP(player)
if exist('XP.mat','file')
load('XP.mat')
else disp('No experience mat file found.');
return
end</pre><pre> XPexist = false;
for j = 1:size(experience,1)
if strcmp(experience{j,1},player.Name)
player.XP = experience{j,2};
XPexist = true;
end
if j==size(experience,1) && ~XPexist
player.XP = 0;
end
end
end
end
end</pre><p>classdef Pfighter < player & fighter</p><pre> % player class hierarchy
% handle
% |
% character
% |
% ------------------------------------------------
% | | | |
% AI wizard fighter player
%
% Cwizard (AI&wizard), Cfighter(AI&fighter), Pwizard (player&wizard), Pfighter(player&fighter)</pre><pre> properties</pre><pre> end</pre><pre> methods
function obj = Pfighter(obj)
obj.Class = 'Pfighter';</pre><pre> end
end</pre><p>end</p>Brett Spanglerhttps://www.mathworks.com/matlabcentral/profile/authors/5365214-brett-spanglertag:www.mathworks.com,2005:Question/4067792018-06-21T13:54:59Z2018-06-22T15:37:11Zplotting very slow and took a long time for the plot tool to show up<p>I am plotting 50 graphs in the same plot with these few lines. The data are already in the workspace.</p><p>figure; hold on</p><p>for n = 1:50</p><p>plot(x, y,'LineWidth',2.0);</p><p>hold on</p><p>end</p><p>The figure window shows up within 5 seconds, but it takes MATLAB 3 minutes to populate the graph window with the graphs. Additionally, when I try to use the plot tools to modify the figure, each icon I click or each action I did takes ~ 10 seconds to act, including some simple action like moving the legend position or click to select a specific graph. My computer practically froze while waiting. Initially I thought plotting 50 is too much, but when I try to plot 10 it took about the same amount of time and memory % which is something I've never saw before.</p><p>I have a pretty fast computer - an i7 8th generation with 16 GB RAM. I am running on MATLAB R2017b. Running other high memory usage program doesn't have this issue. I have never had this problem with R2017b on another supposedly slower computer - i3 with 32 GB RAM.</p><p>I am more of trying to trouble-shoot if this is the problem of the computer or with MATLAB. Thanks.</p>Melissa Chenhttps://www.mathworks.com/matlabcentral/profile/authors/11319004-melissa-chentag:www.mathworks.com,2005:Question/4069712018-06-22T15:36:30Z2018-06-22T15:36:30ZQuasi newton method for optimization<img src = "/matlabcentral/answers/uploaded_files/122406/obj.PNG"><p>I am trying to solve the above objective function for theta using quasi newton method. But I am getting the following error. Can somebody please help me fix this error?</p><p>Following is my matlab code:</p><p>Code for defining objective function:</p><pre> function f = objfun(x_t,c_n,theta)
t=0:length(x_t)-1;
L=length(t);
n=0:length(c_n)-1;
N=length(n);
for i=1:L
for j=1:N</pre><pre> f=@(theta) sum((x_t(i)-sum(c_n(j).*exp(-((t(i)-n(j)*a)^2/theta^2))))^2)</pre><pre class="language-matlab">end
end
</pre><pre> end</pre><p>Code for calling objective function:</p><pre> a = 1;
x_t=rand(32,1);
c_n=rand(32,1);</pre><pre class="language-matlab">f = @(theta) objfun(x_t,c_n,theta)
</pre><pre class="language-matlab">theta0 = 20;
options = optimoptions('fminunc','Algorithm','quasi-newton');
[theta, thetaval] = fminunc(f,theta0,options)
</pre><img src = "/matlabcentral/answers/uploaded_files/122408/err.PNG">christinahttps://www.mathworks.com/matlabcentral/profile/authors/11850304-christinatag:www.mathworks.com,2005:Question/130052011-08-03T17:52:37Z2018-06-22T15:30:42ZHistogram Y axis to Logarithmic Scale<p>I trying to set the Y- axis of a histogram to Logarithimic Scale. I know I can use Y tick but I trying to figure out how I can get the best formulae for this I would be grateful for any help rendered.</p><p>hist(data(1:29196,3))
set(gca,'YTick',)</p>Anthonyhttps://www.mathworks.com/matlabcentral/profile/authors/2964443-anthonytag:www.mathworks.com,2005:Question/4069572018-06-22T14:25:47Z2018-06-22T15:30:17Zhow to change variable value from another function<p>Hi,
is there any way to change the value of a and b without change the function's signature.
like global variable in c?</p>yon amhttps://www.mathworks.com/matlabcentral/profile/authors/10411473-yon-amtag:www.mathworks.com,2005:Question/4069692018-06-22T15:19:01Z2018-06-22T15:19:01ZStep response of Estimated model in SID toolbox.<p>Hello, I am trying to find model of my system using matlab's system identification toolbox. why i get step response of estimated model which settles at 0.05 instead of 1. Model shows good fit to validation data but residual analysis is bad. Thanks.</p>Amaresh Mandalhttps://www.mathworks.com/matlabcentral/profile/authors/11854004-amaresh-mandaltag:www.mathworks.com,2005:Question/4069682018-06-22T15:14:50Z2018-06-22T15:14:50ZProcessor-in-the-loop Arduino simulation with double data type<p>I want to perform processor in the loop simulations of a subsystem (controller) in my model on an Arduino Uno board. I successfully generate a PIL block, however I run into the following error message when I start the simulation:</p><pre> Data type "double" is not supported for SIL or PIL execution with the current target configuration. This is because the host size (8 bytes) and target size (4 bytes) do not match. To avoid this error, do not use this data type at the component interface.</pre><p>I've tried using the single precision conversion tool with no effect and also tried surrounding the subsystem with the respective conversion blocks.</p>Kaloyan Yordanovhttps://www.mathworks.com/matlabcentral/profile/authors/11140825-kaloyan-yordanovtag:www.mathworks.com,2005:Question/4069162018-06-22T08:35:17Z2018-06-22T15:09:41ZHow can I simulate motion blur due to camera and object movement?<p>Hi, I want to simulate motion blur of an image due to camera and object movement. I know I can use the MATLAB function fspecial so blur the image due to camera movement since the function applies the same 2D filter to the whole image which is exactly what happens when there is camera movement (e.g. the whole image is blurred). But in the case of motion blur due to object movement only part of the image is blurred since the background is stationary. What is the easiest method of simulating motion blur due to a moving object? I want to combine it with the motion blur due to camera movement. This in effect means that the image will be blurred to a "greater" extend in the region of the object than in the background (e.g. The background will ONLY have motion blur due to camera movement and the region of the object will have a COMBINED motion blur due to camera and object movement). An answer to an efficient way of combining the 2 types of motion blur (e.g. motion blur due to camera and object movement) will also be appreciated.</p><p>Regards
Johann Berrangé</p>Johann Berrangéhttps://www.mathworks.com/matlabcentral/profile/authors/13054801-johann-berrangetag:www.mathworks.com,2005:Question/4069582018-06-22T14:31:31Z2018-06-22T15:06:53ZHow to make linear fit?<p>Hi;
I want to plot a linear fit for the graphic in the attached file.
And also I want to calculate slope of this linear fit?
How can I do this? File is in the attached file..
Thanks a lot.</p>nancyhttps://www.mathworks.com/matlabcentral/profile/authors/5885586-nancytag:www.mathworks.com,2005:Question/4069672018-06-22T15:06:45Z2018-06-22T15:06:45ZError when using matlab and labspec via activex as a bridge<p>Hi,
I try to use matlab and activex as a bridge to control labspec Raman spectrometer. I am able to load the activex driver in matlab R2007b (32 bit) with the command :</p><p>LabSpec=actxserver('NFACTIVEX.NFActiveXCtrl.1');</p><p>and use simple command like :</p><p>LabSpec.AboutBox;</p><p>This command open a dialog box with the version of the labspec software. However, when I'm asking for a more complex function, like moving the XYZ stage :</p><p>LabSpec.MoveMotor('X',0,'',0);</p><p>I got the following error : ??? Error: Object returned error code: 0x7941E804</p><p>Does someone have any clue to resolve that?</p>François Dionhttps://www.mathworks.com/matlabcentral/profile/authors/13056383-francois-diontag:www.mathworks.com,2005:Question/4068102018-06-21T16:06:07Z2018-06-22T15:06:25ZHow can I open a generic EXCEL file ?<p>Hi,</p><p>the procedure to access a spreadsheet data from MATLAB running an Excel application in an Automation server is well known and explained at the matlab Documentation. As an example, something like this is seen:</p><p>exl = actxserver('excel.application');</p><p>exlWkbk = exl.Workbooks;</p><p><b>exlFile = exlWkbk.Open([docroot '/techdoc/matlab_external/examples/input_resp_data.xls']);</b></p><p>I need to open a generic file from Excel (something you wold do otherwise at the Command Window through winopen(cd) ). I would like to have the possibility to chose the file and don't let it fix.</p><p>Thank you.</p>Fernandahttps://www.mathworks.com/matlabcentral/profile/authors/12336997-fernandatag:www.mathworks.com,2005:Question/4069442018-06-22T13:16:18Z2018-06-22T15:05:35ZMerge L and b channels in LAB color space <p>Is it possible to merge two channels in a color space other than RGB?</p>Mirett Boliardhttps://www.mathworks.com/matlabcentral/profile/authors/13055185-mirett-boliardtag:www.mathworks.com,2005:Question/4069662018-06-22T15:00:29Z2018-06-22T15:00:29ZHow Long stay MCR_CACHE_MEMORY in temp folder?<p>How Long stay MCR_CACHE_MEMORY in temp folder?</p>Selva Karnahttps://www.mathworks.com/matlabcentral/profile/authors/4733665-selva-karnatag:www.mathworks.com,2005:Question/4065892018-06-20T15:22:02Z2018-06-22T14:59:13ZHow to improve a Thz image quality ?<p>Hello everyone,</p><p>I'd like to know how to improve the image that comes from a terahertz camera with matlab ?
the image is linked, I also have a video, can I work on the video to improve the image?
Thanks in advance</p>newport portnewhttps://www.mathworks.com/matlabcentral/profile/authors/13044640-newport-portnew