https://it.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions20170725T14:42:18Ztag:it.mathworks.com,2005:Question/35018020170725T13:59:15Z20170725T14:42:18ZHow to move array data to additional columns based on repeats in a vector or column<p>I have an array like A (below) with duplicates in the second column, for example there are three 1's,three 6's and four 7's. What I would like to do is either have a separate array for each block (to include all the multiples) or preferably be able to move the data for the multiples in the 3rd and 4th columns to the same row as the first element but in extra columns I could preallocate for? i have some code to move the duplicates out onto the same row and replace the original data with nans but cannot get them all on one row.</p><pre class="languagematlab">A=[ 1 1 1.0277 0.56932
2 1 1.0426 0.4202
3 1 1.048 0.42017
4 2 1.1466 0.48309
5 6 1.4731 0.4024
6 6 1.5244 0.62436
7 6 1.5295 0.40456
8 7 1.55 0.58695
9 7 1.5658 0.41037
10 7 1.6107 0.4693
11 7 1.6248 0.62088
12 8 1.7182 0.48]
</pre><pre class="languagematlab">for k=2:size(A)
if A(k,2)==A(k1,2)
A(k1,5)=A(k,3)
A(k1,6)=A(k,4)
A(k,3)=nan
A(k,4)=nan
</pre><pre> end
end</pre><p>Best regards</p><p>Steve</p>Stephen Devlinhttps://it.mathworks.com/matlabcentral/profile/authors/7937501stephendevlintag:it.mathworks.com,2005:Question/34977620170721T19:32:14Z20170725T14:41:34Zhow to find the best curve fit for a set of data<p>i have a set of data which i want to curve fit.
how i can determine the best curve fit of it using MATLAB and cftool ?
i have to write an script or what?</p>Maryam Maparhttps://it.mathworks.com/matlabcentral/profile/authors/10626884maryammapartag:it.mathworks.com,2005:Question/25866720151203T07:34:16Z20170725T14:41:09ZVertices of polygons in bounded voronoi diagram<p>I am new to matlab and I am facing a problem as follows.</p><p>I want to find out the vertices of polygons that make up the voronoi diagram limited by a rectangular boundary. I was trying to use 'Voronoin' function but I am not able to think of a way to extract out the vertices of the bounded polygons. Voronoin gives us vertices of unbounded polygons and not that of bounded version. Besides it also treats both posotive and negative infinities as Inf only.
So, please help me.</p>Hitarth Mishrahttps://it.mathworks.com/matlabcentral/profile/authors/7362669hitarthmishratag:it.mathworks.com,2005:Question/35018720170725T14:40:10Z20170725T14:40:10Zis there is any alternate solution for this "P=freqcp(numpl,denpl,w);" command?<p>clc;
clear all;
close all;
tic
k = 1:0.5:10;
a = 1:0.5:5;
n1 = numel(k);
n2 = numel(a);
numpl = repmat(k, 1, n2)';
denpl = repmat([ones(n2,1), a.', zeros(n2,1)] ,n1, 1);
w=[.1,.5,.8,1,2,8,15,50,100];
P=freqcp(numpl,denpl,w);</p><p>% plot templates
plottmpl(w,w,P);</p><p>time=toc</p>Anita pawarhttps://it.mathworks.com/matlabcentral/profile/authors/10581527anitapawartag:it.mathworks.com,2005:Question/12316920140326T11:49:00Z20170725T14:38:20ZHow to delete leading zeros in a row vector in MATLAB?<p>I have created a function which multiplies two factorials together in MATLAB and the final result is:</p><p>0000000000000000000000000000000000000000</p><p>0000000000000005127485891768928006848657</p><p>3067757467756330382900027197934928341442</p><p>4644048874750576347830749966301579885959</p><p>6864463688769208320000000000000000000000</p><p>00</p><p>I need to delete the leading zeros, without deleting the trailing zeros.
Anyone know how to do this?</p><p>Would help a lot, thanks</p>Emilyhttps://it.mathworks.com/matlabcentral/profile/authors/5190515emilytag:it.mathworks.com,2005:Question/35018620170725T14:34:29Z20170725T14:34:29ZDetect laser beam break from live video<p>I am attempting to write a program to detect a break in a laser beam. A circular array of beams will be seen (Think dots on the vertices of a hexagon) by a USB camera and the program will run a function when one of the beams is not seen (is blocked). The program must detect the beam break and run the function as fast as possible. Being somewhat new to image processing, I am not sure of the fastest/most computationally efficient way to accomplish this. Any help is greatly appreciated. Thanks!</p>will rowleyhttps://it.mathworks.com/matlabcentral/profile/authors/4046391willrowleytag:it.mathworks.com,2005:Question/35018520170725T14:33:28Z20170725T14:33:28ZSolving DARP using linprog function Matlab.<p>I'm trying to solve the Dial A Ride Problem using MILP, see paper: https://link.springer.com/content/pdf/10.1007/s1047900701708.pdf. I'm using the linprog function of Matlab, but I'm having trouble defining my matrices and vectors for the different constraints.</p><p>Does anyone have an example code for this type or a similar problem like the VRP? Any help or tips are appreciated!</p>Peter Voshttps://it.mathworks.com/matlabcentral/profile/authors/6813816petervostag:it.mathworks.com,2005:Question/35015820170725T11:19:41Z20170725T14:30:13ZConvert a struct to an Object of a class.<p>Hi everybody,</p><p>I have problem concerning the Construction of a userdefined class.</p><p>I have class called C and a struct S with excactly the same fields. Now I would like to create an Instance of my Class that sets its properties corresponding to the struct S.</p><p>Is there any command I can use (actually like an opposite struct(obj) ) ? I tried it with the command class, but this didn't work out.</p><p>I would be glad if somone could help me.</p><p>Best regards,
Boris</p>Boris Pasternackhttps://it.mathworks.com/matlabcentral/profile/authors/6339235borispasternacktag:it.mathworks.com,2005:Question/35016520170725T12:09:28Z20170725T14:29:59ZHow to build a screw model by simscape?<p>Now I want to study Stick slip effect of screw. And I don't know how kann i build this Model. First of all, i chose to use SimMechanics. But i found that, there is no friction block. Then my teacher tell that, i should use Simscape foundation library. Here there is friction block, but i think this is very difficult to achieve this motion of screw only by foundation library. So can i build a model to study stick slip effect of screw by simscape?</p>Dongbohttps://it.mathworks.com/matlabcentral/profile/authors/10639946dongbotag:it.mathworks.com,2005:Question/34943020170719T14:09:24Z20170725T14:26:44ZUsing activex control for word  no spacing between paragraphs<p>Word seems to default to paragraphs taking up two spaces. I wan it to make a MATLAB code that will generate a report, but when I use the command selection.TypeParagraph it does a double space, as is the default.
I cannot seem to find a way of changing this so that there is no spacing.
I'm new to activex. The basic idea of the code is below. Any help much appreciated! (Using 2016a, windows)
I want it to output</p><p>Text here:</p><p>Second line of text:</p><p>But currently it is outputting as...</p><p>Text here:</p><p>.</p><p>Second line of text:</p><p>word = actxserver('Word.Application');
word.Visible = 1;
document = word.Documents.Add;
selection=word.Selection;</p><p>selection.TypeText('Text here:');
selection.TypeParagraph
selection.TypeText('Second line of text:');</p>James Boylehttps://it.mathworks.com/matlabcentral/profile/authors/8291374jamesboyletag:it.mathworks.com,2005:Question/35018320170725T14:19:46Z20170725T14:22:48ZI HAVE TO FIND OUT SCORE OF MATRICS AND THAT SCORE SHOULD BE A MATCS <p>A= 1, 4, 7, 2, 4, 9, 3, 8, 2;</p><img src = "/matlabcentral/answers/uploaded_files/83762/PICSSSS.png">wali Muhammadhttps://it.mathworks.com/matlabcentral/profile/authors/10640414walimuhammadtag:it.mathworks.com,2005:Question/35018420170725T14:19:59Z20170725T14:21:16ZDisplay range of a clustegram<p>Dear all,</p><p>I have been trying to set a display range for my clustergrams but the way I see it, if the annotated values inside the clustergram are below my desired Display Range, Matlab acts on a different way. It sets the upper and lower colorbar display range based on the maximum value inside the clustergram instead of scaling to my desired display range. I don't have this problem when the annotated values inside the clustergram are above my Display Range. This is the code that I typed:</p><pre class="languagematlab">cgo_all = clustergram(data,'Colormap',redbluecmap, ...
'DisplayRange',3,'Symmetric', true, 'ColumnLabels', columns,...
'RowLabels', rows);
</pre><p>So I expect the upper and lower colorbars adjusted to 3 and 3, respectively, but you can check the attachment to see what I get as an image (both annotated and unannotated).</p><p>I am looking forward to your help and thanks in advance.</p><p>Cheers,</p>bari atahttps://it.mathworks.com/matlabcentral/profile/authors/4800255bariatatag:it.mathworks.com,2005:Question/35018120170725T14:02:32Z20170725T14:16:07ZHow to create a gridded matrix with N equally spaced points?<p>I am trying to create a coordinate grid with equally spaced rows of N data points in the format of X and Y values.</p><p>How can I specify this in terms of maximum and minimum values ofX and Y values I want, so that I can create a table of points?</p>matlabkid602https://it.mathworks.com/matlabcentral/profile/authors/10515763matlabkid602tag:it.mathworks.com,2005:Question/35017520170725T13:30:23Z20170725T14:08:14ZGUIDE slider callback within another running callback won't update handles altered during the slider callback<p>Hi everyone,</p><p>i am currently working on a GUI for a program i have written in Matlab and have come across a problem where i just can't figure out how to resolve it. Researches didn't really help for my specific case. I hope someone here can help me out.</p><p>So basically, my GUI has one start pushbutton, when pressed, my program will be started in the pushbutton_Callback. The .mfile contains a forloop to subsequently display video frames on a axes in the GUI. So it basically looks like a video player, and the code processes some information on the individual frames and displays the results on the frames right away. Now i am trying to add a slide bar, which the user can operate on, even when the pushbutton_Callback is still running. What i am looking for is, when the slide bar is operated during pushbutton_Callback, the slider_Callback should output a handle called handles.slider_moved (value = 1) and the pushbutton_Callback picks up this changed handle and terminates its execution by the use of return. Now the problem is, that the handle slider_moved doesn't get updated after the slider_Callback has finished running (local scope within the slider_Callback), so the "if handles.slider_moved" condition is never met in the pushbutton_Callback(see belowing example code):</p><pre class="languagematlab">function pushbutton_Callback(hObject,eventdata,handles)
handles.slider_moved = 0;
for i = currentFrame:totalFrame
...
if handles.slider_moved
return;
end
end
</pre><pre class="languagematlab">function slider_Callback(hObject,eventdata,handles)
handles.slider_moved = 1;
calculate frame number corresponding to the new slider value...
guidata(hObject,handles)
</pre><p>I tried</p><pre class="languagematlab">function handles = slider_Callback(hObject,eventdata,handles)
</pre><p>and it didn't change anything.</p><p>What i want in the end is the following:</p><p>when slide bar is moved during video play (meaning pushbutton_Callback still running), play the video starting from the frame/time corresponding to the new position of the slider. And terminating the current pushbutton_Callback is the first step in doing so.</p><p>I'm grateful for any kind of advices. If there are better methods to achieve the end goal, please enlighten me!</p><p>Thanks alot in advance.</p>Jian Zhouhttps://it.mathworks.com/matlabcentral/profile/authors/10449436jianzhoutag:it.mathworks.com,2005:Question/35018220170725T14:07:21Z20170725T14:07:21ZWhat is the Main Difference between Simulink Desktop Real Time and Simulink Real Time Kernels?<p>What is the main difference (advantages / disadvantages) between Simulink Desktop RealTime (SLDRT) kernel and Simulink RealTime(SLRT) kernels? Do we use both of the for realtime (External Mode) applications, i.e. PIDControl? or not.</p>DesoliDshttps://it.mathworks.com/matlabcentral/profile/authors/8141964desolidstag:it.mathworks.com,2005:Question/35016820170725T12:57:33Z20170725T14:06:26ZHow to solve a linear system of equations<p>I have to solve a linear system written inside an handle function, which returns a column vector. I have tried to solve it by using "fsolve" as follows:</p><p>y=fsolve(@afun,y0,options)</p><p>In this way the result was correct.
Now I would like to solve it with a linear solver.The system is written in the following form:</p><pre class="languagematlab">function f = system(y)
f(1) = y(1)+2*y(2)3;
f(2) = y(2)+3*y(3)4;
f(3) = y(1)+4*y(2)+6*y(3)3;
end
</pre><p>There is an easy way to do it without writing the coefficient matrix of the system? I need it because often I work with very large system of equations.</p>simone campanellahttps://it.mathworks.com/matlabcentral/profile/authors/6513216simonecampanellatag:it.mathworks.com,2005:Question/34967120170721T02:49:38Z20170725T13:54:48ZHow to perform stratified 10 fold cross validation for classification in MATLAB?<p>My implementation of usual Kfold crossvalidation is pretty much like:</p><pre class="languagematlab">K = 10;
CrossValIndices = crossvalind('Kfold', size(B,2), K);
</pre><pre class="languagematlab">for i = 1: K
display(['Cross validation, folds ' num2str(i)])
IndicesI = CrossValIndices==i;
TempInd = CrossValIndices;
TempInd(IndicesI) = [];
xTraining = B(:, CrossValIndices~=i);
tTrain = T_new1(:, CrossValIndices~=i);
</pre><pre> xTest = B(:, CrossValIndices ==i);
tTest = T_new1(:, CrossValIndices ==i);
end</pre><p>But To ensure that the training, testing, and validating dataset have similar proportions of classes (e.g., 20 classes).I want use stratified sampling technique.Basic purpose is to avoid class imbalance problem.I know about SMOTE technique but i want to apply this one.</p>Machine Learning Enthusiasthttps://it.mathworks.com/matlabcentral/profile/authors/8198354machinelearningenthusiasttag:it.mathworks.com,2005:Question/35017920170725T13:46:22Z20170725T13:49:52Zhow to convert java.util.Vector into a matrix<p>I have a Java.util.Vector</p><pre class="languagematlab">myData=[[0, 1, 1, 1, 1], [0, 0, 1, 1, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0]]
</pre><p>want to convert this into matrix as</p><pre> M= 0 1 1 1 1
0 0 1 1 1
0 0 0 1 1
0 0 0 0 1
0 0 0 0 0</pre><p>Thanks in advance.</p>Sanjeev Kumarhttps://it.mathworks.com/matlabcentral/profile/authors/10423479sanjeevkumartag:it.mathworks.com,2005:Question/35017420170725T13:29:46Z20170725T13:46:58Zi have 10 folders and in each folder i have 20 images...for a folder i need to extract histogram normalization values of images and i need to store them for further use...i have written code but im unable to get stored values...help me ..thanks<pre class="languagematlab">clear all;
close all;
Folder='G:\C\New folder (2)\(2)';
file1=fullfile(Folder,'*.png');
pngimages1=dir(file1);
numOfFiles=length(pngimages1);
for i=1:length(pngimages1)
FileName1=pngimages1(i).name;
fullFileName1=fullfile(Folder,FileName1);
im1=imread(fullFileName1);
im11=rgb2gray(im1);
im111=imhist(im11)./numel(im11);
im112=im111(i,:);
end
xlswrite('myFile.xlsx',im112);
</pre>Gohanhttps://it.mathworks.com/matlabcentral/profile/authors/8864943gohantag:it.mathworks.com,2005:Question/34909320170717T15:22:24Z20170725T13:46:08ZHow to implement a mutliobjective optimization with the creation of pareto spaces? Currently developed code provides incorrect results.<p>Currently, I am trying to solve a multiobjective optimization problem in MATLAB R2012a (student version).</p><p>I've already implemented most steps in a script (code is provided at the end of this question), but the results do not meet my expectations.</p><p>The following list provides a brief overview of the implemented steps and where problems occur:</p><ul><li>Quality check of Monte Carlo output</li><li>Calculation of objective functions for each run and year</li><li>Selection of the objective functions for the Pareto Space</li><li>Creation of a "Pseudo Pareto Space", based on allowed measurement uncertainties</li><li>Calculation of the Pareto Space (based on Pseudo Pareto Space): <b>Problem:</b> I don't get the right indices to identify the appropriate model run.</li></ul><p>This gives rise to the following <b>questions</b>:</p><ol><li>How do I get the right indices to identify the appropriate model run?</li></ol><p>Does anyone have an idea how to solve this question?</p>Glaziohttps://it.mathworks.com/matlabcentral/profile/authors/3394266glaziotag:it.mathworks.com,2005:Question/35000420170724T12:20:17Z20170725T13:44:21Zthe simulation is shown in a single figure as a movie. I want to export the movie and play with some external player.<p>dt = 1;
t = 1:dt:30;
Nt = length(t);
Du = 10;
Dv = 5;</p><p>u=zeros(64,64);
u(27:36,27:36)=ones(10,10)</p><p>v=rand(64,64);</p><p>hold on;
for j = 1:Nt</p><p>Nextu=u+(Du*del2(u));
u=Nextu;
Nextv=v+(Dv*del2(v));
v=Nextv;</p><pre> figure(1)
surface(Nextu)</pre><pre> colormap gray</pre><pre> colorbar</pre><p>end</p>Soumya Ranjan Sahuhttps://it.mathworks.com/matlabcentral/profile/authors/9919918soumyaranjansahutag:it.mathworks.com,2005:Question/35017820170725T13:41:58Z20170725T13:41:58ZDynamic Scan DICOM File how to seperate into frames by number of counts<p>Hi,</p><p>I have a DICOM file of a 'Dynamic Scan' which has 15000 frames.
I would like to sum each frame until it reaches 20M counts and then loop to continue and sum until the entire set of frames has been split into 20M count files.
How would I go about doing this?</p><p>Thanks.</p>Nicholas Bateshttps://it.mathworks.com/matlabcentral/profile/authors/4300892nicholasbatestag:it.mathworks.com,2005:Question/35017020170725T13:07:44Z20170725T13:41:07Zvectorize a loop or two so that the program runs faster <p>can someone help me vectorize a loop or two so that my program runs faster? It runs but the results take AGES.. Here is the whole code. Thank you!!!</p><pre class="languagematlab">clear all
clc
%%
noise_Levels = 3;
number_signals = 4;
MSE_CV = zeros(number_signals,noise_Levels);
MSE_plugIN = zeros(number_signals,noise_Levels);
MSE_Mean_Max_SNR = zeros(number_signals,noise_Levels);
MSE_maxSNR = zeros(number_signals,noise_Levels);
MSE_Poly_SNR = zeros(number_signals,noise_Levels);
</pre><pre class="languagematlab">%for j = 1:noise_Levels
% j
kernelShape = 'Tricube';
</pre><pre> %********************%COMPLEX SINE******************************
% w=[0.0:0.01:1.01]';
% w=repmat(w,5,1); %repmat(w,10,1);
%
% t=[ones(100,1)];
% for i=2:5
% t=[t;i*ones(100,1)];
% end
% %stpFunc = abs(sin(2*pi*w.*t)); %+6*sigma;
% stpFunc = sin(2*pi*w.*t); %+6*sigma;
% n = length(stpFunc);
% %plot(stpFunc)
% origFun = stpFunc';
%****************************************************************</pre><pre> %********************SINE****************************************</pre><pre class="languagematlab">% X = linspace(0,4*pi,100);
% N=length(X);
% ySignal=(X5).^2+10;
% ySignal=sin(X);
% origFun = ySignal;
% y = origFun;
% n = length(y);
%****************************************************************
</pre><pre> %************** Polynomial function******************************
cc = 1000;
x = [1:cc]/cc;
origFun =(x0.5).*(x0.25).*(x0.75).*20+10;
y = origFun;
n = length(origFun);
%****************************************************************</pre><pre> %%
bwStep = [0.001:0.001:0.004,0.005:0.01:0.2];
p = 1;
% x = [1:length(stpFunc)]/length(stpFunc);
x = [1:n]/n;
X = x;
%x = rand(n,1);
spc = 1/n;
bwSpc = round( bwStep / spc );</pre><pre class="languagematlab">for j = 1:noise_Levels
j
for iLoop = 1:number_signals
[ycnoise,bwpl,yHatPlugIn,yHatCV,yHatSNRAll,yHatSNR,yHatSNRfinalBW,yHatSNRmeanBW,sigma,cvScore,cvBW] = FCN_AR_1_2_W(X',origFun',p,bwStep,x',kernelShape);
format short g
MSE_CV(iLoop,j) = (1/length(ycnoise))*sum((yHatCV(j,:)  origFun).^2);
MSE_plugIN(iLoop,j) = (1/length(ycnoise))*sum((yHatPlugIn(j,:)  origFun).^2);
MSE_Mean_Max_SNR(iLoop,j) = (1/length(ycnoise))*sum((yHatSNRmeanBW(j,:)  origFun).^2);
MSE_maxSNR(iLoop,j) = (1/length(ycnoise))*sum((yHatSNRAll(j,:)  origFun).^2);
MSE_Poly_SNR(iLoop,j) = (1/length(ycnoise))*sum((yHatSNRfinalBW(j,:)  origFun).^2);
end
end
</pre><p>The main part that needs to be vectorized is this part</p><pre class="languagematlab">for j = 1:noise_Levels
j
for iLoop = 1:number_signals
[ycnoise,bwpl,yHatPlugIn,yHatCV,yHatSNRAll,yHatSNR,yHatSNRfinalBW,yHatSNRmeanBW,sigma,cvScore,cvBW] = FCN_AR_1_2_W(X',origFun',p,bwStep,x',kernelShape);
format short g
MSE_CV(iLoop,j) = (1/length(ycnoise))*sum((yHatCV(j,:)  origFun).^2);
MSE_plugIN(iLoop,j) = (1/length(ycnoise))*sum((yHatPlugIn(j,:)  origFun).^2);
MSE_Mean_Max_SNR(iLoop,j) = (1/length(ycnoise))*sum((yHatSNRmeanBW(j,:)  origFun).^2);
MSE_maxSNR(iLoop,j) = (1/length(ycnoise))*sum((yHatSNRAll(j,:)  origFun).^2);
MSE_Poly_SNR(iLoop,j) = (1/length(ycnoise))*sum((yHatSNRfinalBW(j,:)  origFun).^2);
end
end
</pre>Osita Onyejekwehttps://it.mathworks.com/matlabcentral/profile/authors/7728673ositaonyejekwetag:it.mathworks.com,2005:Question/35003620170724T15:36:19Z20170725T13:40:33ZLatex interpreter with sentences and symbols<p>I use latex interpreter when add labels to my plots and no problem appears when I write whole sentences without symbols or only symbols; however, when I try to combine them, there is no error, but neither does it work. Does anyone have any idea of how it could be fixed? I tried typing $$ instead of just $, but still that way.
Thank you in advance.</p>Aparicio Nietohttps://it.mathworks.com/matlabcentral/profile/authors/6287661aparicionietotag:it.mathworks.com,2005:Question/35017720170725T13:39:27Z20170725T13:39:27Zhow to configure matlab for a C ++ compiler ?<p>I am working on Matlab version 2016b , i already have a microsoft visual c++ 2013 installed in my system. But when i give the mex  setup command , i am getting the following message....
No supported compiler or SDK was found. You can install the freely available MinGWw64 C/C++ compiler; see Install MinGWw64 Compiler.</p><p>I tried downloading this compiler as well but didnt work....</p>Anoop Thomashttps://it.mathworks.com/matlabcentral/profile/authors/10538299anoopthomastag:it.mathworks.com,2005:Question/34985620170722T18:11:13Z20170725T13:37:16ZCalculating the distance between every two points of a list?<p>Hello everybody</p><p>I have a trajectory like this: We assume that each red star marker can broadcast its coordinate to the green circle markers which are located within a radius of 5 units from its own position.I selected a list of n red points for each green marker according to the above explanation.</p><p>How can I calculate the euclidean distance between every two red points of the list and the select the maximum euclidean distance corresponding red points?
Thanks.</p><img src = "/matlabcentral/answers/uploaded_files/83552/Rand.jpg"><pre class="languagematlab">%% Network Setup
anchor_num=1; % Number of anchor node
node_num=20; % Total nodes
length1=70; % Area length
anchor_x=0; % Intial position of anchor x coordinate
anchor_y=0; % Intial position of anchor y coordinate
anchormove=[];% Anchor trajectory
width=40; % Area width
r = 30;
A = zeros(0,2);
B = zeros(0,2);
C = zeros(0,2);
D = zeros(0,2);
north = [ 0 6.9];
east = [ 6.9 0];
south = [ 0 6.9];
west = [6.9 0];
order = 4;
for n = 1:order
AA = [B ; north ; A ; east ; A ; south ; C];
BB = [A ; east ; B ; north ; B ; west ; D];
CC = [D ; west ; C ; south ; C ; east ; A];
DD = [C ; south ; D ; west ; D ; north ; B];
A = AA;
B = BB;
C = CC;
D = DD;
end_
% Plot network trajectory
%Mtrix A contains the coordinate of red markers.
A = [0 0; cumsum(A)]
p=plot(A(:,1),A(:,2))
title('Plot of Hilbert trajectory');
set(p,'Color','magenta ','LineWidth',2);
axis([0 100 0 100]);
hold on
% x and y are the coordinates of green markers
x=rand(1,100)*100;
y=rand(1,100)*100;
scatter(x,y)
</pre><pre class="languagematlab">anchormove(1,:)=A(:,1)'
anchormove(2,:)=A(:,2)'
idx=length(anchormove(1,:));
for i=1:idx1
% Plot the moving anchor node
Ax=anchormove(1,i);
Ay=anchormove(2,i);
plot(Ax,Ay,'r*');
% Plot transmission range of the anchor node
axis([0 100 0 100])
% hold on
pause(0.1)
%hold off
% turn the two x and y vectors into [x y] column format.
GreenPoints = [x;y].';
% get indexes of the points A for each Green point within 5 distance
idx = rangesearch(A,GreenPoints,5);
end
</pre>Zeinab Ahmadi93https://it.mathworks.com/matlabcentral/profile/authors/10469847zeinabahmadi93tag:it.mathworks.com,2005:Question/34977520170721T19:20:36Z20170725T13:33:22Zadditional simscape electronics floating reference?<pre> Hi,
is there a way to create a simscape component that acts like a floating reference to simplify drawings for use with simscape electronics in matlab 2016a?
I am working on electrical DCDC involving transformer for isolation of primary and secondary side. On primary side I can use multiple electrical reference blocks to simplify drawing, on secondary side I need to connect everything together.
Regards,
Tsing</pre>Tsing Hsuhttps://it.mathworks.com/matlabcentral/profile/authors/5961836tsinghsutag:it.mathworks.com,2005:Question/35017620170725T13:32:48Z20170725T13:39:57ZHow should I write a custom driver in order to perform Analog Input / Output operations with an unsupported Advantech Hardware using Simulink Desktop Real Time?<p><b>Description of Problem:</b></p><p>I have recently bought an <i>Advantech PCIe1816H DAQ card</i> in order to implement a realtime SISO (MISO) control application (with sampling rates up to 20 KHz) inside the Simulink software <b>(Simulink Desktop Real Time (SLDRT) kernel)</b> using a <b>64bit MATLAB / Windows 10</b>. (I have previously performed realtime control applications using <i>Advantech PCI1710HG, PCI1720 DAQ cards</i> on a 32bit MATLAB / Windows).
So far, the Advantech Company has not supported its DAQ cards on a 64bit version of MATLAB. In other words, no MATLAB DAQ Adaptor kit is released by Advantech Company.</p><p><b>I want to write my own customized Analog Input / Output Blocks to be able to communicate with <i>Advantech DAQ cards (PCI1710HG, PCI1720, PCIe1816H)</i> on a 64bit SIMULINK / Windows using SLDRT kernel.</b>
Both MATLAB and Advantech DAQNavi help documentations have Software Development Kit (SDK) sections which describe how to extend the functionality of the MATLAB DAQ / IMAQ toolboxes as well as Advantech DAQ cards. Yet, I do not know how to solve my problem? And where to start from? I have got a little bit confused, due to the huge amount of data around this subject.</p><p><b>Extra Details:</b></p><p>1) <a href = "https://www.mathworks.com/help/imaq/creatingcustomadaptors.html">The MATLAB Documentation</a> provides a template for development of custom DAQ / IMAQ adaptors in order to support new hardware via MATLAB Data Acquisition / Image Acquisition toolboxes. In the given examples a directory of C++ source files / header files are compiled in order to build a 64bit MEX (MATLAB Executive) file. Some of the required files are related to the vendor device driver and library of API functions provided by hardware vendor (As provided by Advantech Company in its DAQNavi software package). In fact, the functionality of this MEX file is to connect the MATLAB DAQ / IMAQ toolbox to the Hardware Device Driver. Finally, the newlyregistered hardware can be accessed by the Data Acquisition toolbox via the SessionBased Interface.
Should I follow this approach in order to develop my customized Advantech I/O device drivers for realtime data acquisition using SLDRT kernel?</p><p>2) The Simulink Real Time (SLRT) software provides an environment to write a device driver for unsupported hardware boards via SFunctions <a href = "https://www.mathworks.com/matlabcentral/fileexchange/39354devicedrivers">(Please refer to Device Driver Guide)</a> and <a href = "https://www.mathworks.com/help/xpc/customdevicedrivers.html">(Please refer to Simulink Documentation)</a> . The Simulink RealTime software has its own kernel, and you write the device drivers aimed at that kernel. Are the developed I/O blocks (via SFunctions) can be used with SLDRT Kernel. In other words, should I follow this approach in order to develop my customized Advantech I/O device drivers for realtime data acquisition using SLDRT kernel? Is this approach applicable to PCIe DAQ boards?</p><p>3) According to <a href = "https://www.mathworks.com/help/sldrt/ug/customiodriverbasics.html">The Simulink Desktop RealTime Documentation</a> , the Data Acquisition boards, provided by various hardware vendors, are often used for data acquisition independently of Simulink Desktop RealTime software. In such environments, board manufacturers usually provide their own I/O Device Drivers for data acquisition purposes. This type of usage differs significantly from the behavior of drivers provided with Simulink Desktop RealTime software.
So the question that arises is: What are the requirements of developing a custom realtime I/O Device Driver for Advantech (or any other manufacturer) hardware applicable inside <b>Simulink Desktop RealTime software</b>?</p><p><b>Conclusion:</b></p><p>What is the best solution for creating a custom IO device driver (adaptor) for an unsupported Hardware (Here Advantech DAQ boards) in order to perform basic Analog Input and Analog Output operations in a real time control application (with MATLAB 64bit SLDRT kernel)? and what are the most important requirements?</p>DesoliDshttps://it.mathworks.com/matlabcentral/profile/authors/8141964desolidstag:it.mathworks.com,2005:Question/9298120120426T02:00:00Z20170725T13:32:03ZWhy do I get an error when using XLSREAD in a BATCH job submitted to a Windows cluster managed by MathWorks Job Scheduler in MATLAB Distributed Computing Server 6.0 (R2012a)?<p>I am using a Windows cluster managed by MathWorks Job Scheduler.</p><p>I have a 'xlsReadTest.m' file is a script that contains a call to XLSREAD as follows:</p><pre class="languagematlab">[numData,textData,rawData] = xlsread('Test_SR.xlsx');
numProc = numel(numData);
results = NaN(size(numData));
parfor loopProc = 1:numProc
results(loopProc) = numData(loopProc) + 20;
end
</pre><p>When I run the 'xlsReadTest.m' script as a batch job with the following command:</p><pre class="languagematlab">batch(schedObj,'xlsReadTest','Matlabpool',31,'FileDependencies', {'xlsReadTest.m','Test.xlsx'});
</pre><p>I obtain the following error message:
ERROR: ErrorIdentifier: MATLAB:COM:E2148140012
ErrorMessage: Invoke Error, Dispatch Exception:
: Source: Microsoft Office Excel
: Description: Microsoft Office Excel cannot access the file '..\..\Test.xlxs'.</p><p>If I use XLSREAD in basic mode, I am able to read the data.</p>MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813mathworkssupportteamtag:it.mathworks.com,2005:Question/35017220170725T13:17:43Z20170725T13:31:44Zfind peaks of a signal <p>Hi,</p><p>i am working on a project and i need to find peaks of a signal , for every acquisition of 20s we have 1 pic every 4 seconds.
I use the function findpeaks but this function gives just 1 pic and ignore the 4 others.
I want know how to resolve this problem
Thanks for help
hear is my code</p><pre class="languagematlab">clear;
S= [48.37 22.6011
49.66 26.5161
48.89 30.4361
65.29 30.4711
57.54 34.3561
52.18 38.2761 ]
</pre><pre> [pks,locs] = findpeaks(S(:,1));
plot(S(:,2),S(:,1))
grid
hold
plot(S(locs,2),pks,'.r','MarkerSize',23)</pre><img src = "/matlabcentral/answers/uploaded_files/83751/Capture.PNG">mdsteronehttps://it.mathworks.com/matlabcentral/profile/authors/10585231mdsteronetag:it.mathworks.com,2005:Question/21461020150501T14:51:02Z20170725T13:29:22ZIs there someway I can use the eeglab toolbox with matlab online?<p>Since the eeglab toolbox is free (and if I am not mistaken uses the signal processing toolbox which comes with the matlab online?) is there someway I could download the eeglab tool box on a computer and then use it with my matlab online account? (I don't want to use the standalone version of eeglab since it doesn't work as well)</p>Grusha Prasadhttps://it.mathworks.com/matlabcentral/profile/authors/6465107grushaprasadtag:it.mathworks.com,2005:Question/35008920170724T22:14:28Z20170725T13:28:13ZMatlab code for the following<p>How do i use central differencing for x=sint(t) over the interval 0 to 2pi with 2nd order accuracy?</p>Velika D'Souzahttps://it.mathworks.com/matlabcentral/profile/authors/10257265velikadsouzatag:it.mathworks.com,2005:Question/35016920170725T13:06:37Z20170725T13:41:33ZBig data question. how to generate a variable efficiently and aggregate <p>I have a file of tens of millions observations with a string identifier, which I load as a datastore:</p><ol><li>............. V1 ..... V2 ............ V3 ........ V4</li><li># # * # KLM88 20010630 10 COMPANY1</li><li># # * # KLM88 20001231 20 COMPANY1</li><li># # * # MNH7C 20010930 23 COMPANY1</li><li># # * # MNH7C 20010630 15 COMPANY1</li><li># # * # MNH7C 20001231 6 COMPANY1</li><li># # * # HG9LB 20001231 2 COMPANY1</li></ol><p>I also have a mat file with some extra information and matching of first variable:</p><ol><li># KLM88 COUNTRYA</li><li># MNH7C COUNTRYA</li><li># HG9LB COUNTRYB</li></ol><p>I wish for an end result such that I aggregate on country and date and company my dataset :</p><ol><li># * # 20010930 23 COMPANY1 COUNTRYA</li><li># * # 20010630 25 COMPANY1 COUNTRYA</li><li># * # 20001231 26 COMPANY1 COUNTRYA</li><li># * # HG9LB 20001231 2 COMPANY1 COUNTRYB</li></ol><p>I know I can do so by reading per dataChunk and with for loop assigning the country. However, that takes a huge amount of time. Any other suggestions of how to do so?
I am fairly new to the concepts of tall arrays/ mapreduce etc. Thus, I am not sure how could I arrive to what I want more efficiently.</p>HELLO_MAhttps://it.mathworks.com/matlabcentral/profile/authors/8142761hello_matag:it.mathworks.com,2005:Question/35003920170724T16:01:21Z20170725T13:27:14ZIs there any way to speed up the calculation of the confluent hypergeometric function ?<p>Hello Friends,
Matlab's hypergeom function is too slow for my model calibration. Is there any other function to use or other way to increases the speed ?</p><p>Thank you</p>Andrei Vaipanhttps://it.mathworks.com/matlabcentral/profile/authors/10621259andreivaipantag:it.mathworks.com,2005:Question/35017320170725T13:23:11Z20170725T13:26:26ZError when building code for C2000 MCU in external mode<p>Hi all! ;)</p><p>I want to run a Simulink model on my Texas Instruments F28069M (C2000 Microcontroller) in exernal mode, so that I can change certain parameters and view certain values on the scope online, i.e. during operation.
I already set up the serial communication between laptop and MCU according to this documentation: <a href = "https://www.mathworks.com/help/supportpkg/texasinstrumentsc2000/examples/parametertuningandsignalloggingwithserialexternalmode.html?s_tid=gn_loc_drop">https://www.mathworks.com/help/supportpkg/texasinstrumentsc2000/examples/parametertuningandsignalloggingwithserialexternalmode.html?s_tid=gn_loc_drop</a>
However, I get an error message when I want to compile and run the model. The message looks like this:</p><pre class="languagematlab">C:/TI_CCSv6/ccsv6/tools/compiler/TICGT~1.STS/bin/cl2000 compile_only large_memory_model cla_support=cla0 silicon_version=28 define="LARGE_MODEL" i"/~SupportFiles/DSP280x_headers" i"/~SupportFiles/DSP280x_headers/include" i"C:/TI_CCSv6/ccsv6/tools/compiler/TICGT~1.STS/include" v28 ml float_support=fpu32 define="EXTMODE_DISABLEPRINTF" v28 ml float_support=fpu32 DMODEL=Communication_Test DNUMST=1 DNCSTATES=0 DHAVESTDIO DON_TARGET_WAIT_FOR_START=1 DONESTEPFCN=1 DEXT_MODE=1 DTERMFCN=0 DMAT_FILE=0 DMULTI_INSTANCE_CODE=0 DINTEGER_CODE=1 DMT=0 DCLASSIC_INTERFACE=0 DALLOCATIONFCN=0 DTID01EQ=0 D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ DRT DSTACK_SIZE=512 DONESTEPFCN=1 DEXT_MODE=1 DTERMFCN=0 DMAT_FILE=0 DMULTI_INSTANCE_CODE=0 DINTEGER_CODE=1 DMT=0 DCLASSIC_INTERFACE=0 DALLOCATIONFCN=0 DTID01EQ=0 DON_TARGET_WAIT_FOR_START=1 DRT DSTACK_SIZE=512 DMODEL=Communication_Test DNUMST=1 DNCSTATES=0 DHAVESTDIO IC:/Users/Armin/Documents/MATLAB/Communication_Test_ert_rtw IC:/Users/Armin/Documents/MATLAB IC:/PROGRA~1/MATLAB/extern/include IC:/PROGRA~1/MATLAB/simulink/include IC:/PROGRA~1/MATLAB/rtw/c/src IC:/PROGRA~1/MATLAB/rtw/c/src/ext_mode/common IC:/PROGRA~1/MATLAB/rtw/c/ert IC:/PROGRA~1/MATLAB/toolbox/coder/rtiostream/src/utils IC:/MATLAB_Packages/texasinstrumentsc2000/toolbox/target/supportpackages/tic2000/src IC:/PROGRA~1/MATLAB/toolbox/target/extensions/processor/tic2000/include IC:/PROGRA~1/MATLAB/toolbox/rtw/targets/common/can/blocks/tlc_c IC:/MATLAB_Packages/texasinstrumentsc2000/toolbox/target/supportpackages/tic2000/inc IC:/TI_ControlSUITE/device_support/f2806x/v151/F2806x_common/include IC:/TI_ControlSUITE/device_support/f2806x/v151/F2806x_headers/include IC:/PROGRA~1/MATLAB/toolbox/shared/can/src/scanutil output_file="MW_c28xx_board.obj" "MW_c28xx_board.c"
C:/TI_CCSv6/ccsv6/tools/compiler/TICGT~1.STS/bin/cl2000 compile_only large_memory_model cla_support=cla0 silicon_version=28 define="LARGE_MODEL" i"/~SupportFiles/DSP280x_headers" i"/~SupportFiles/DSP280x_headers/include" i"C:/TI_CCSv6/ccsv6/tools/compiler/TICGT~1.STS/include" v28 ml float_support=fpu32 define="EXTMODE_DISABLEPRINTF" v28 ml float_support=fpu32 DMODEL=Communication_Test DNUMST=1 DNCSTATES=0 DHAVESTDIO DON_TARGET_WAIT_FOR_START=1 DONESTEPFCN=1 DEXT_MODE=1 DTERMFCN=0 DMAT_FILE=0 DMULTI_INSTANCE_CODE=0 DINTEGER_CODE=1 DMT=0 DCLASSIC_INTERFACE=0 DALLOCATIONFCN=0 DTID01EQ=0 D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ DRT DSTACK_SIZE=512 DONESTEPFCN=1 DEXT_MODE=1 DTERMFCN=0 DMAT_FILE=0 DMULTI_INSTANCE_CODE=0 DINTEGER_CODE=1 DMT=0 DCLASSIC_INTERFACE=0 DALLOCATIONFCN=0 DTID01EQ=0 DON_TARGET_WAIT_FOR_START=1 DRT DSTACK_SIZE=512 DMODEL=Communication_Test DNUMST=1 DNCSTATES=0 DHAVESTDIO IC:/Users/Armin/Documents/MATLAB/Communication_Test_ert_rtw IC:/Users/Armin/Documents/MATLAB IC:/PROGRA~1/MATLAB/extern/include IC:/PROGRA~1/MATLAB/simulink/include IC:/PROGRA~1/MATLAB/rtw/c/src IC:/PROGRA~1/MATLAB/rtw/c/src/ext_mode/common IC:/PROGRA~1/MATLAB/rtw/c/ert IC:/PROGRA~1/MATLAB/toolbox/coder/rtiostream/src/utils IC:/MATLAB_Packages/texasinstrumentsc2000/toolbox/target/supportpackages/tic2000/src IC:/PROGRA~1/MATLAB/toolbox/target/extensions/processor/tic2000/include IC:/PROGRA~1/MATLAB/toolbox/rtw/targets/common/can/blocks/tlc_c IC:/MATLAB_Packages/texasinstrumentsc2000/toolbox/target/supportpackages/tic2000/inc IC:/TI_ControlSUITE/device_support/f2806x/v151/F2806x_common/include IC:/TI_ControlSUITE/device_support/f2806x/v151/F2806x_headers/include IC:/PROGRA~1/MATLAB/toolbox/shared/can/src/scanutil output_file="Communication_Test.obj" "Communication_Test.c"
"C:/TI_ControlSUITE/device_support/f2806x/v151/F2806x_headers/include/F2806x_Device.h", line 136: warning: typedef name has already been declared (with same type)
"C:/TI_ControlSUITE/device_support/f2806x/v151/F2806x_headers/include/F2806x_Device.h", line 136: error: expected a ";"
1 error detected in the compilation of "Communication_Test.c".
>> Compilation failure
gmake: *** [Communication_Test.obj] Error 1
The make command returned an error of 2
The command "An_error_occurred_during_the_call_to_make" is either written wrong or could not be found.
### Build procedure for model: 'Communication_Test' aborted due to an error.
Error(s) encountered while building "Communication_Test":
### Failed to generate all binary outputs.
</pre><p>It seems that the header files provided by TI contain an error. But that is not likely to be possible, so there might be something wrong with Simulink or Embedded Coder. Or are there some important setup steps which I missed? Does anyone know a solution?</p><p>Best regards,
Armin</p>Armin Lenskerhttps://it.mathworks.com/matlabcentral/profile/authors/8081143arminlenskertag:it.mathworks.com,2005:Question/35015620170725T11:09:09Z20170725T13:20:14ZHow can I estimate the velocity of object without the time?<p>Hi everyone;
My code is here;</p><pre class="languagematlab">%Creating video input
clc; clear all;
</pre><pre class="languagematlab">vid = videoinput('macvideo',1,'YCbCr422_1280x720');
</pre><pre class="languagematlab">%Specify number of frames to acquire trigger with using video source
vid.FramesPerTrigger=inf;
</pre><pre class="languagematlab">%Specify how often to acquire frame from video stream
set(vid,'ReturnedColorspace','rgb');
</pre><pre class="languagematlab">vid.FrameGrabInterval=5;
</pre><pre class="languagematlab">%Starting webcam
</pre><pre class="languagematlab">%vid.FrameRate = 30;
</pre><pre class="languagematlab">start(vid);
</pre><pre class="languagematlab">for i=1:100
%Acquiring images in a specific loop
</pre><pre> data = getsnapshot(vid);
%Subtract on image from another or subtract constant from image</pre><pre> data_gray = imsubtract(data(:,:,1),rgb2gray(data));
%2D median filtering
data_gray = medfilt2(data_gray,[3,3]);
%Convert image to binary image, based on threshold
%The output of the image BW replaces all pixels in the input image
%with luminance level which is range from 0 to 1.
data_gray = im2bw(data_gray,0.24);
%Removing needless images
data_gray = bwareaopen(data_gray,100);
bw = bwlabel(data_gray,8);
%The object is marked with this function</pre><pre> stats = regionprops(bw,'BoundingBox','Centroid');</pre><pre> %Picking the video on the 1280x720 chart
image(data)
hold on</pre><pre> for(object = 1:length(stats))
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2);
%Marking the object(s)
plot(bc(1),bc(2),'m+');
%Coordinates are displayed in centimetres form.
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))*0.019), 'Y: ', num2str(round(bc(2))*0.022)));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
%disp('Vel: ',num2str(sqrt((bc(1)).^2 + bc(2).^2))./vid.FrameRate)</pre><pre> end
hold off</pre><pre> end
stop(vid);
flushdata(vid);</pre><p>I'll be glad if you can help me.</p>Kivanc Demirhttps://it.mathworks.com/matlabcentral/profile/authors/9232709kivancdemirtag:it.mathworks.com,2005:Question/35015520170725T11:04:58Z20170725T13:20:05ZGive priority to gui callback over code<p>Hi,</p><p>I'm having some issues right now that I would need to be sorted. Here is the situation :</p><p>I need to monitor some data, and I want to do it through an interface. (I used the app designer functions)</p><p>I have a main program, and an interface which should display some data from the main running program.</p><p>The function to generate the interface is called from the main program so that it can have access to the handles.</p><p>In order to disturb the main program as little as possible, I put a "Refresh" button on the interface. The "refresh" callback function is nested in the main program. This function updates all the fields of the interface so that it shows the updated data from the main program.</p><p>Since I'm starting with some tests, I did this at first :</p><pre class="languagematlab">tic;
while toc < 30
value = toc;
pause(1);
end
</pre><p>With this first test, the refresh button works, my value is displayed in the interface as expected.</p><p>But then, I did this :</p><pre class="languagematlab">tic;
while toc < 30
value = toc;
end
</pre><p>Now, clicking on the button will not trigger any change in the interface. It seems that the callback nevers runs until I terminate the program.</p><p>Is there any way I can get that fixed ? I cannot afford to leave this "pause" function since the actual main program is supposed to monitor animal behaviour...</p>Guillaume Penderiahttps://it.mathworks.com/matlabcentral/profile/authors/8302040guillaumependeriatag:it.mathworks.com,2005:Question/34943820170719T14:47:30Z20170725T13:16:53ZHow to debug mex files under Emacs, Ubuntu<p>How to debug mex files from Emacs under Ubuntu? R2017a and Emacs 24 are in use.</p><p>D.</p>tianhttps://it.mathworks.com/matlabcentral/profile/authors/4552543tiantag:it.mathworks.com,2005:Question/34985520170722T18:08:48Z20170725T13:16:45ZI am trying to create a feature vector from the dataset of english character images, my dataset includes total of 62 characters. 26 CAPITAL, 26 small, and 10 numerals. However, my code shows problems with [singleSubFolder, remain] = strtok(remain, ';<pre class="languagematlab">% Start with a folder and get a list of all subfolders.
% Finds and prints names of all PNG, JPG, and TIF images in
% that folder and all of its subfolders.
% Similar to imageSet() function in the Computer Vision System Toolbox: http://www.mathworks.com/help/vision/ref/imagesetclass.html
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
</pre><pre class="languagematlab">% Define a starting folder.
start_path = fullfile(English, '\Fnt');
% Ask user to confirm or change.
topLevelFolder = uigetdir(start_path);
if topLevelFolder == 0
return;
end
% Get list of all subfolders.
allSubFolders = genpath(topLevelFolder);
% Parse into a cell array.
remain = allSubFolders;
listOfFolderNames = {};
while true
[singleSubFolder, remain] = strtok(remain, ';');
if isempty(singleSubFolder)
break;
end
listOfFolderNames = [listOfFolderNames singleSubFolder];
end
numberOfFolders = length(listOfFolderNames) ;
</pre><pre class="languagematlab">% Process all image files in those folders.
for k = 1 : numberOfFolders
% Get this folder and print it out.
thisFolder = listOfFolderNames{k};
fprintf('Processing folder %s\n', thisFolder);
% Get PNG files.
filePattern = sprintf('%s/*.png', thisFolder);
baseFileNames = dir(filePattern);
% Now we have a list of all files in this folder.
if numberOfImageFiles >= 1
% Go through all those image files.
for f = 1 : numberOfImageFiles
fullFileName = fullfile(thisFolder, baseFileNames(f).name);
fprintf(' Processing image file %s\n', fullFileName);
end
else
fprintf(' Folder %s has no image files in it.\n', thisFolder);
end
end
</pre>Bishal Bishthttps://it.mathworks.com/matlabcentral/profile/authors/10516663bishalbishttag:it.mathworks.com,2005:Question/35009520170724T23:45:27Z20170725T13:13:52ZWhy is the 'activeset' algorithm being removed from LSQLIN when the alternative 'interiorpoint' algorithm lacks the same performance?<p>I'm providing an example of a problem that is typical in our use of LSQLIN. We solve a physics based problem where all the constraints are required to ensure a physically real solution. Solving problems like this are at the core of a much larger problem, where LSQLIN is called ~10,000 times per problem. As the LSQLIN ‘interior_point’ algorithm doubles computational time, the removal of ‘activeset’ makes our data processing speed slow down significantly. I understand that 'activeset' may not be available in the future. Does Mathworks plan on addressing what seems to be a downgrade of the LSQLIN to an inferior state? Will ‘interiorpoint’ ever offer the same performance as ‘activeset’?</p><p>Variables C, d, A and b can be loaded from the attached MATfile.
C: is full and 45x6
d: 45x1
A: 9x6 each row has 3 nonzero values.
b: 9x1 zeros array</p><pre class="languagematlab">load example
tic; x1 = lsqlin(C, d, A, b, [], [], [], [], [], optimoptions(@lsqlin,'Algorithm', 'activeset','Display','off')); toc
tic; x2 = lsqlin(C, d, A, b, [], [], [], [], [], optimoptions(@lsqlin,'Algorithm', 'interiorpoint','Display','off')); toc
Elapsed time is 0.002902 seconds.
Elapsed time is 0.006580 seconds.
</pre>David Sinexhttps://it.mathworks.com/matlabcentral/profile/authors/4992527davidsinextag:it.mathworks.com,2005:Question/35006520170724T18:57:01Z20170725T13:11:10ZIn SIMULINK, how can I get the time corresponding to my particular output of of a function block?<p>For example I have my function y=f(t) and I want to assign the time corresponding to y=k, to T1. k is const.</p>Santhosh Naiduhttps://it.mathworks.com/matlabcentral/profile/authors/10591425santhoshnaidutag:it.mathworks.com,2005:Question/35017120170725T13:10:42Z20170725T13:10:42Z1st post: How do I optimize 3 sets of inputs, so when 2 are known the optimal value in the third set is selected?<p>Hi everyone, this is my first post and I have only started using MATLAB and Simulink a week ago for my project. So I have an optimization problem more specifically a hybrid. So the efficiency depends on three variables (propulsion load power, state of charge of battery and the torque split) and I want to essentially produce a lookup table. So in real time when the propulsion load and state of charge are known a optimum torque split value is selected which optimizes the efficiency. So say the range of values for propulsion load is 30 to 60 in 1kw increments and battery charge is form 50 to 80% in 1% increments, there are 10 torque split settings.In simulink how do I calculate the efficiency for every single combination of the 3 variables to produce a efficiency control map? Thank you!!</p>Zhenteng Shenhttps://it.mathworks.com/matlabcentral/profile/authors/10558177zhentengshentag:it.mathworks.com,2005:Question/35007320170724T19:57:41Z20170725T13:10:20Zhow to add blank columns to table<p>I have a table with 100200 rows and ~400 columns. I want to add a blank (empty) column at 34 specified points in between some of the existing columns. This will segregate the data and make it more readable...sort of like adding a column in Excel.</p><p>I can't seem to find the right command(s). Any help?</p>Stephenhttps://it.mathworks.com/matlabcentral/profile/authors/4676522stephentag:it.mathworks.com,2005:Question/35014920170725T10:08:20Z20170725T13:01:00Zhow to convert character array to cell array<p>hello,
i have a char array of size 1280 * 8 ...
values like 11111111
01010101
10100101
........
01010101
Now i want as 1*10240 cell array (since 1280 * 8 =10240)...output must be 1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1.....i used str2num ..but they were being conatanated as vertical..i want to conctanate horizantally/..</p>Jyothi Alugoluhttps://it.mathworks.com/matlabcentral/profile/authors/9669677jyothialugolutag:it.mathworks.com,2005:Question/35016320170725T12:04:50Z20170725T12:56:28ZHow do you run a script with a button in a function?<p>I have a (simplified) script called Holecheck. This script contains an important variable 'I':</p><pre class="languagematlab">if
%code
else if
%code
else
run Doesnotfit
end
end
</pre><p>Doesnotfit is a function looking as follows:</p><pre class="languagematlab">function Doesnotfit
</pre><pre class="languagematlab">I=evalin('base','I');
</pre><pre class="languagematlab">%stop=evalin('base','stop');
% I = 0;
%fgh = figure('position',[1100,30,210,60]);
</pre><pre class="languagematlab">uicontrol('Parent',figure(2), 'Style', 'Pushbutton', 'String', 'Go left',...
'Position',[0.1,0.1,50,20], 'Callback', @Ileft);
uicontrol('Parent',figure(2), 'Style', 'Pushbutton', 'String', 'Go right',...
'Position',[100,0.1,50,20], 'Callback', @Iright);
uicontrol('Parent',figure(2), 'Style', 'Pushbutton', 'String', 'Accept',...
'Position',[50,0.1,50,20], 'Callback', @Iaccept);
mTextBox = uicontrol('Parent',figure(2),'style','text');
set(mTextBox,'String',num2str(I))
</pre><pre> function Ileft(~,~)
I=I1
assignin('base', 'I', I)
set(mTextBox,'String',num2str(I))
end</pre><pre> function Iright(~,~)
I=I+1
assignin('base', 'I', I)
set(mTextBox,'String',num2str(I))
end</pre><pre> function Iaccept(~,~)
Holecheck
end
end</pre><p>In short, there are three buttons and a text. The first two buttons add 1 or 1 to variable 'I'. When last button (Iaccept) is pressed, the script should automatically run the starting file 'Holecheck' again from the start. However, I get the following error:</p><p>Attempt to add "Xout" to a static workspace.
See Variables in Nested and Anonymous Functions.</p><p>Error in Holecheck (line 2)
Xout=500;</p><p>Error in Doesnotfit/Iaccept (line 31)
Holecheck</p><p>Error while evaluating UIControl Callback</p><p>I have already read something about 'Variables in Nested and Anonymous Functions' but i still don't understand.</p><p>Please can you help me?
Thanks</p>Rick van den Hadelkamphttps://it.mathworks.com/matlabcentral/profile/authors/6494395rickvandenhadelkamptag:it.mathworks.com,2005:Question/35016720170725T12:48:32Z20170725T12:48:32ZSImulink Arduino Serial Receive  variable data size<p>Is it possible to somehow configure serial communication with Arduino to recieve data that varies in size?</p><p>I want to send text commands using terminal application to Arduino board  the text of course will be converted to ascii and on arduino side there will be a program that interprets commands and acts accordingly.</p><p>The problem? Text commands will not always be of even length one will take 8x uint8 and other will take 10x uint8. What is the issue? Both Arduino Serial Receive and Instruments Control Serial Receive are forcing me to specify data size right from the start and then when i attempt to send a data that size is smaller than what is configured in blocks, the data will be not transferred until it reaches enough size which looks like this:</p><p>> Serial receive set to 4 x uint8</p><p>> Sending 'X' from terminal > Arduino not letting data through
> Sending 'X' from terminal > Arduino not letting data through
> Sending 'X' from terminal > Arduino not letting data through
> Sending 'X' from terminal > Arduino suddenly receives whole XXXX at once instead one by one</p>Konradhttps://it.mathworks.com/matlabcentral/profile/authors/10496651konradtag:it.mathworks.com,2005:Question/27538420160325T07:31:21Z20170725T12:45:25Zxlswrite error  worksheet could not be activated<p>Dear Matlab users,</p><p>Last week my Matlab started to return an error when trying to export data into excell. For example:</p><p> command and error message:</p><pre class="languagematlab">>> xlswrite('myfile',data)
</pre><pre class="languagematlab">Error using xlswrite (line 219)
</pre><pre class="languagematlab">Excel Worksheet could not be activated.
</pre><p> error object:</p><pre class="languagematlab">The exception object (from line 219) reads:

</pre><pre class="languagematlab">identifier : 'MATLAB:xlsread:WorksheetNotActivated'
message: 'Excel Worksheet could not be activated.'
cause: 0x0 cell (authors tesxt: an empty cell)
</pre><p></p><p>I can export to other types of files (csv, txt,...)</p><p>I am having a hard time understanding what the problem is. I am using my office computer. It might be related to our security policy. Our IT department could not help me.</p><p>Anyone had any similar experience and found a solution?</p><p>Thank you for your help and kind regards,</p><p>Vasja</p>vasja sivechttps://it.mathworks.com/matlabcentral/profile/authors/5106097vasjasivectag:it.mathworks.com,2005:Question/35016620170725T12:40:28Z20170725T12:40:28ZTransition condition of Stateflow as Parameter<p>Hello Everyone. Is it possible to set a transition condition of Stateflow as something like "maskparameter" or variables? Many thanks!</p>Yuntao Zhanghttps://it.mathworks.com/matlabcentral/profile/authors/9220107yuntaozhangtag:it.mathworks.com,2005:Question/31497520161201T18:27:46Z20170725T12:34:42ZGUI toolbar frozen by uiwait command<p>I created a GUI in Guide that includes axes and a toolbar to zoom and pan. I added uiwait to OpeningFcn and uiresume on a button callback, to allow user input prior to returning the output to a script from the OutputFcn. But now the toolbar no longer works. I need the toolbar function before the ouput is returned. How can I get the toolbar to work?</p>Rachel S.https://it.mathworks.com/matlabcentral/profile/authors/2375148rachelstag:it.mathworks.com,2005:Question/35010420170725T01:19:00Z20170725T12:28:30ZNeed help in MATLAB GUI<p>I am writting my question first time in MATLAB Central,
I want to create the GUI using one push button and check box.
In my GUI I read the text file in the while loop and plot the data of text file data using push button and check box.
The purpose of push button plot the point plotting
while the check box plots the data as trajectory
When I push pushbutton so the simulation do just point plotting while hitting check box simulation performs continuous plotting from that current point.
please help I spent 4 days but couldnt find the way two link the check box and push button in MATLAB GUI</p><p>I attach my code to this question</p>Sairah Naveedhttps://it.mathworks.com/matlabcentral/profile/authors/10323051sairahnaveed