https://ch.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions20171019T10:41:12Ztag:ch.mathworks.com,2005:Question/36211420171019T10:07:35Z20171019T10:41:12ZMy GUI won't open on next 'Run' after a close command<p>Hi,</p><p>I have a GUI function which I want to run and then close when I press a button.</p><p>In the main file which calls the GUI I have a while = 1 loop. On button press, the GUI sets a variable to 0, which is supposed to stop the loop in the main file and close the GUI.
This works, the GUI closes itself and the program stops, but when I go to press Run again, the GUI won't open.
The workaround fix is to make an edit to the GUI file and save it  pressing space and then ctrl+s. After this it will run from the main file successfully.</p><p>Can anyone tell me why this is and give me a proper fix not this workaround</p><p>Here is the GUI:</p><pre class="languagematlab">function [GuiCtrl_fn] = GUI()
</pre><pre class="languagematlab">GuiCtrl_fn = [];
persistent Title;
persistent CloseBtn;
persistent figureGUI;
</pre><pre class="languagematlab">if isempty(figureGUI)
figureGUI = figure('position',[400 400 400 400],...
'name','File Management',...
'numbertitle','off',...
'resize','OFF',...
'color', [0.94 0.94 0.94]);
end
%%
if isempty (Title)
Title = uicontrol(figureGUI, 'Style', 'text',...
'FontSize',16,...
'Position',[0 365 400 30],...
'String', 'File Management');
end
%%
if isempty(CloseBtn)
img=imread('close.png');
CloseBtn=uicontrol(figureGUI, 'style','pushbutton',...
'units','pixels',...
'position',[355 355 44 44],...
'cdata',img,...
'callback', {@close});
end
</pre><pre> function [] = close(varargin)
% Callback for close button.
assignin('base', 'GuiCtrl_fn', 0);
end</pre><pre class="languagematlab">end
</pre><p>And the GUI gets called from another .m file</p><pre class="languagematlab">GuiCtrl = 1 ;
disp('Opening GUI');
</pre><pre class="languagematlab">while GuiCtrl == 1
[GuiCtrl_fn] = GUI_file_manage();
pause(0.02);
if isempty (GuiCtrl_fn)
else
GuiCtrl = GuiCtrl_fn;
disp(GuiCtrl);
pause(0.02);
end
end
close all;
</pre>Will Hawardhttps://ch.mathworks.com/matlabcentral/profile/authors/9030898willhawardtag:ch.mathworks.com,2005:Question/36210420171019T08:53:18Z20171019T10:37:50ZConversion of {} in () with cell2table <p>I have this cell array :</p><img src = "/matlabcentral/answers/uploaded_files/91505/1.PNG"><p>I do this command :</p><pre class="languagematlab">data = cell2table(data, 'VariableNames',{'Date' 'ap' 'cp'});
</pre><p>And I have this :</p><img src = "/matlabcentral/answers/uploaded_files/91507/2.PNG"><p>My problem is that the third column has the {} (like data.cp{61,1} in the example), while the second column has the () (like data.ap(61,1) in the example)</p><p>Why do I get this ? And how can I fix it ? I would like to have () for both</p><p>Thanks</p>Louis TERRATShttps://ch.mathworks.com/matlabcentral/profile/authors/7236988louisterratstag:ch.mathworks.com,2005:Question/36208820171019T07:32:05Z20171019T10:37:15ZWarning while loading .mat file<p>Dear all,
when I load a .mat file I get the following error</p><pre class="languagematlab">if true
% code
Warning: Variable 'sbas_s_EGDUErrOnOff_mte_writeEnable' originally saved as a VWSim.Signal cannot be
instantiated as an object and will be read in as a cell.
end
</pre>sourav sahoohttps://ch.mathworks.com/matlabcentral/profile/authors/8431054souravsahootag:ch.mathworks.com,2005:Question/36200820171018T18:35:18Z20171019T10:35:05ZFunction does a thing for an amount of time, then another thing.<p>Basically, I'm trying to replicate a Closed Transfer Switch in a Matlab Function. I have two inputs (two power sources) and two outputs. For simplicities sake, I have set it up so that when the first inputs rises above a specific value, that input will then drop to 0 and input 2 will flow through output 2. However, the behaviour of Closed Transfer Switches results in a brief moment of paralleling, where, for 100ms or less, both power sources are connected, so therefore, in this case, both inputs flow through the outputs.</p><p>I have had a stab at programming a function to achieve this. I don't really understand why it doesn't seem to be working as I've used the "etime" function to determine the time in which both outputs should be flowing. This isn't working and I really don't understand why. I've used a couple of functions to try simplify things a bit for myself but again, doesn't seem to be working.</p><p>Closed Transfer Switch Function.</p><pre> %Closed Transfer Switch Function
function [y1, y2] = CTS(u1, u2)</pre><pre> coder.extrinsic('clock')</pre><pre> t0=clock;
u1=0;
u2=0;
y1=0;
y2=0; </pre><pre> if abs(u1) > 20
[y1, y2] = Para(u1, u2, t0);
else
[y2, y1] = Para(u2, u1, t0);
end</pre><p>Paralleling Function</p><pre class="languagematlab">function [out1, out2] = Para(in1, in2, s)
</pre><pre class="languagematlab">coder.extrinsic('clock')
coder.extrinsic('etime')
</pre><pre class="languagematlab">in1=0;
in2=0;
out1=0;
out2=0;
</pre><pre class="languagematlab">if etime(clock, s) < 0.1
out1=in1;
out2=in2;
else
out1=0;
out2=in2;
end
</pre><p>Does anyone know why this isn't working? Any help would be much appreciated! Thanks all for your time! Ali.</p>Alasdair Robertsonhttps://ch.mathworks.com/matlabcentral/profile/authors/10564007alasdairrobertsontag:ch.mathworks.com,2005:Question/36195020171018T12:20:05Z20171019T10:33:05ZIs there a way to convert table consists of many variables to matrix ? <p>Is there a way to convert table consists of many variables to a matrix ?</p>Fadal Sassehttps://ch.mathworks.com/matlabcentral/profile/authors/7076758fadalsassetag:ch.mathworks.com,2005:Question/36211220171019T09:33:45Z20171019T10:28:30Zhow to translate and rotation a curve?<p>I have one parabola and one circle. they are separated. i want to translate and rotate one of them so that they touch each other. How can I do that?</p>vikas mishrahttps://ch.mathworks.com/matlabcentral/profile/authors/11285984vikasmishratag:ch.mathworks.com,2005:Question/36210620171019T09:05:44Z20171019T10:26:22ZHow to solve undefined operator error in integral2<p>Hello,</p><p>I want to numerically integrate using integral2 as my function has two variables.
However, I always get the error 'Undefined operator '/' for input arguments of type 'function_handle'.'
I already searched for help but found nothing that helped me.</p><p>Here is my code:</p><pre class="languagematlab">a = 0.15;
v = 1.5e5;
rho = 1.2;
u = @(x,y)(a.*x.*exp(y.*sqrt(a./v)));
v = @(y)(sqrt(a.*v).*(exp(y.*sqrt(a./v))1));
dudx = @(y)(a.*exp(y.*sqrt(a./v)));
dudy = @(y)(a.*exp(y.*sqrt(a./v)));
f = @(x,y)(rho.*(u(x,y).*dudx(y) + v(y).*dudy(y)));
F = integral2(f, 0, sqrt(v/a), 0, inf)
</pre>Aaron Löwensteinhttps://ch.mathworks.com/matlabcentral/profile/authors/10997367aaronlowensteintag:ch.mathworks.com,2005:Question/36189820171018T07:28:33Z20171019T10:22:39ZWhat are Estimated coefficients parameters (Estimate, SE, tStat, pValue) when we do the linear regression model by the command fitlm?<p>Hello,</p><p>If you try the matlab example about linear regression by the following code:</p><pre class="languagematlab">load carsmall
tbl = table(Weight,Acceleration,MPG,'VariableNames',{'Weight','Acceleration','MPG'});
tbl(1:5,:)
lm = fitlm(tbl,'MPG~Weight+Acceleration')
</pre><p>It will generate the following answer:</p><img src = "/matlabcentral/answers/uploaded_files/91325/Capture.PNG"><p>It means that MPG is linearly proportional to weight and acceleration and a constant value. But I don't understand how?
I mean I don't understand what these parameters (Estimate, SE, tStat, pValue) tell me? How should I make the function of the out put with the parameters?</p><p>Many thanks in advance,</p>Kian Azamihttps://ch.mathworks.com/matlabcentral/profile/authors/9888124kianazamitag:ch.mathworks.com,2005:Question/36202820171018T21:05:01Z20171019T10:22:26ZHow do I specify number format in a plot axis in Matlab R2015a?<p>I have a plot in Matlab R2015a which defaults to having yaxis labels formatted in exponential notation.</p><img src = "/matlabcentral/answers/uploaded_files/91438/plot1.PNG"><p>As standard practice I like to go in and reformat the axis labels to have consistent precision (which is an unfortunate shortcoming of pre2016 plots). I do this as follows:</p><pre class="languagematlab">function fixaxislabels( xfrmt,yfrmt )
%fixaxislabels redefines the x and y axis labels to have consistent
% precision IAW xfrmt and yfrmt
xlabel=get(gca,'XTickLabel')
for i=1:numel(xlabel)
xval=str2num(xlabel{i});
xlabel{i}=num2str(xval,xfrmt);
end
ylabel=get(gca,'YTickLabel')
for i=1:numel(ylabel)
yval=str2num(ylabel{i});
ylabel{i}=num2str(yval,yfrmt);
end
xlabel
ylabel
set(gca,'XTickLabel',xlabel);
set(gca,'YTickLabel',ylabel);
</pre><p>However, this only recognizes the actual labels and returns labels between 1.000 and 10.000 rather than 0.001 and 0.010.</p><img src = "/matlabcentral/answers/uploaded_files/91439/plot2.png"><p>How do I force my axis labels to be fixed point notation before I normalize the label precision?</p>Matt Brownhttps://ch.mathworks.com/matlabcentral/profile/authors/6070246mattbrowntag:ch.mathworks.com,2005:Question/36211520171019T10:21:28Z20171019T10:21:28ZI need help with a Matlab script that shows the order of accuracy of the forward and central differencing methods.<p>I'm trying to write a Matlab script that shows the order of accuracy of the forward and central differencing methods for the first derivative of f = exp (x) at x = 0. The graph attached is the result I'm looking for.</p><p>Here is what I have so far in forward differencing method but I'm kinda stuck. Can you show me where I made my mistakes.</p><p>clear all</p><p>close all</p><p>delx = 1;</p><p>x = 0;</p><p>y = exp(x);</p><p>fig = figure();</p><p>set(fig,'color','white')</p><p>plot(x,y,'LineWidth',2)</p><p>xlabel('x')</p><p>ylabel('y')</p><p>grid on</p><p>yderiv = exp(x);</p><p>fig = figure();</p><p>set(fig,'color','white')</p><p>plot(x,yderiv,'LineWidth',2)</p><p>xlabel('x')</p><p>ylabel('y')</p><p>grid on</p><p>%%%Forward Differencing</p><p>yderivest = (y(2:end)  y(1:end1))./delx;</p><p>hold on</p><p>plot(x(2:end)delx/2,yderivest,'r','LineWidth',2)</p>jcn2912https://ch.mathworks.com/matlabcentral/profile/authors/11254897jcn2912tag:ch.mathworks.com,2005:Question/36204720171019T00:23:11Z20171019T10:10:56Zindex exceeds matrix dimension<p>I am coding a problem in which the answer is a matrix and values in the matrix are filled in via loops from the last row and column backwards to the first row and column. I am getting the error "index exceeds matrix dimensions" in line 48 and I don't know why. The exact line is: VNEXT(d+1) = V(SNEXT((d+1)+1,t+1));</p><p>The entire code is:</p><p>function [ V, A ] = inventory( N )
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here</p><p>% initialize PARAMETERS</p><p>FIXCOST = 1;
MARGCOST = 3;
HCOST = 1;
PRICE = 8;
MAX = 3;
NSTATES = MAX  1;</p><p>STATES = (0:MAX);</p><p>DEMAND = (0:2);
PROB = [0.3; 0.3; 0.4];</p><p>V = ones(NSTATES, N) * Inf;
A = zeros(NSTATES, N);</p><p>% set terminal conditions
V(:, N) = 0;
A(:, N) = 1;</p><p>REV = zeros(3,1);
SNEXT = zeros(3,1);
VNEXT = zeros(3,1);</p><p>% Backward Induction
for t = N1:1:1
for s = 1:MAX
for a = 0:MAX  s</p><pre> if (a == 0)
ordercost = 0;
else
ordercost = FIXCOST + MARGCOST * a;
end</pre><pre> u = s + a;
holdcost = HCOST * u;</pre><pre> for d = 0:2
REV(d+1) = PRICE * min(u,d);
SNEXT(d+1) = max(ud,0);
VNEXT(d+1) = V(SNEXT((d+1)+1,t+1));
end</pre><pre> ER = sum(REV .* PROB);
EVNEXT = sum(VNEXT .* PROB);
TOTV = ER + EVNEXT  ordercost  holdcost;</pre><pre> if (V(s+1,t) < TOTV)
V(s+1,t) = TOTV;
A(s+1,t) = a;
end</pre><pre> end
end
end</pre><p>For the line in question I need to index the next row/column to use it in the calculation for the previous row/column value. So d+1 and t+1 must be used.</p>Raymond Watershttps://ch.mathworks.com/matlabcentral/profile/authors/10780431raymondwaterstag:ch.mathworks.com,2005:Question/27518620160324T01:33:36Z20171019T10:08:02ZError "The specified key is not present in this container" when using Matlab Coder<p>When I tried to use Matlab Coder to convert m to c,in the process of verifying mex file, I came across the error message "The specified key is not present in this container".
The algorithm itself can work very well, therefore, I think there may be something wrong in other aspect. In fact, I don't understand the error message at all. Why am I getting this error message? How can I resolve this issue?
Thank you in advance!</p>Leonard Leehttps://ch.mathworks.com/matlabcentral/profile/authors/7889068leonardleetag:ch.mathworks.com,2005:Question/36206720171019T04:12:10Z20171019T10:03:20Z2d triangle moves rotates and bounces<p>The objective of this project is to plot a 2D triangle with three equal sides of length 2, which starts by
being centered at location (0,0), and continuously moves within a square area which is limited between
10 to 10 horizontally and 10 to 10 vertically. The center of the triangle should never exit this 20 x 20
square area. In other words, when the center of the triangle reaches those limits, the triangle should
bounce back so that it stays within the 20 x 20 box. At the same time, the triangle should be rotating
about its center. You may choose the speed with which the triangle moves, and the speed with which
the triangle rotates around its center yourselves. However, the triangle should not be moving just
horizontally or just vertically. Also, it should not be moving with the same speed horizontally and
vertically.
A snapshot of how the triangle should look like within the 10 x 10 box is shown next, in Figure 1:</p><img src = "/matlabcentral/answers/uploaded_files/91467/Capture1.JPG"><p>The following plot in Figure 2 shows how the triangle is moving, rotating, and bouncing at the box
walls. Each color corresponds to a different “snapshot” as the triangle moves</p><img src = "/matlabcentral/answers/uploaded_files/91468/Capture2.JPG"><p>What I got so for is to create triangle and rotate the triangle. I need to move and bounce this triangle the way of question wants. Thank you.
My codes</p><img src = "/matlabcentral/answers/uploaded_files/91469/Capture3.JPG">oguzhan ozelhttps://ch.mathworks.com/matlabcentral/profile/authors/9295280oguzhanozeltag:ch.mathworks.com,2005:Question/105820110208T22:05:18Z20171019T10:00:23ZContributors metainfo: reputation and more<p>As asked by <a href="http://www.mathworks.com/matlabcentral/answers/contributors/2710900vieniava">Vieniava</a> in <a href="http://www.mathworks.com/matlabcentral/answers/1041howtomakealistofusersreputation">"How to make a list of user's reputation?"</a>, some of us came up with interesting ideas on how to fill an <i>updated list</i> with the reputation scores of the contributors to <b>Answers</b>.</p>
<p>I took the initiative to compile a public list of users with meta info:</p>
<ul>
<li>position (desc ordering by reputation)</li>
<li>id</li>
<li>nickname (truncated to fit the page)</li>
<li>reputation</li>
<li># of comments</li>
<li># of questions asked</li>
<li>% accept rate</li>
<li># of posts answered</li>
<li># of accepted answers</li>
</ul>
<p>The code used to compile the list is available at the bottom.</p>
<p><b>EDIT</b></p>
<p>TMW team implemented a page with the metascores: <a href="http://www.mathworks.com/matlabcentral/answers/contributors">http://www.mathworks.com/matlabcentral/answers/contributors</a></p>
<p>Please refer to it and congrats to the team!</p>
<p>Use this function to retrieve info from the link above:</p>
<pre class="languagematlab">function [metainfo, elapsedTime] = metainfo(type,order)
% METAINFO  Retrieve metainfo on contributors to www.matworks.com/.../answers
%
% METAINFO Retrieve data sorted by reputation in descending order
%
% METAINFO(TYPE,ORDER) Specify TYPE and sorting ORDER as
% type : 'reputation'
% 'questions'
% 'answered'
% 'accepted'
%
% order: 'asc'
% 'desc'
%
% Examples:
%
% % Standard call (rep, disc)
% info = metainfo;
%
% % Sort by question answered in descending order
% info = metainfo('an','d');
%
% See also: URLREAD, REGEXP
</pre>
<pre class="languagematlab">% Author: Oleg Komarov (oleg.komarov@hotmail.it)
% Tested on R14SP3 (7.1) and on R2009b. Inbetween compatibility is assumed.
% 28 feb 2011  Created
</pre>
<pre class="languagematlab">tic
</pre>
<pre class="languagematlab">% Check # inputs
error(nargchk(0,2,nargin))
</pre>
<pre class="languagematlab">% Retrieve inputs
if nargin == 0
type = 'reputation';
order = 'desc';
end
if ~exist(type,'var')
sortTypes = {'reputation','questions','answered','accepted'};
type = sortTypes{strncmp(type,sortTypes,numel(type))};
order = 'desc';
end
if ~exist(order,'var')
orderTypes = {'asc','desc'};
type = orderTypes{strncmp(order,orderTypes,numel(order))};
end
</pre>
<pre class="languagematlab">% Build url string
url = ['http://www.mathworks.com/matlabcentral/answers/contributors?'...
'dir=' order '&sort=' type '&page='];
</pre>
<pre class="languagematlab">% First read
[page, ok] = urlread([url '1']);
</pre>
<pre class="languagematlab">% Catch number of pages to read
if ok
totcon = regexp(page,'>1  50 of (\d+)','tokens');
totcon = dataread('string',totcon{1}{1},'%d');
nPages = ceil(totcon/50);
else
error('Cannot read ".../contributors?page=1"')
end
</pre>
<pre class="languagematlab">% Loop over contributors pages
metainfo = cell(totcon,7);
metainfo(1:end,1) = num2cell(1:size(metainfo,1));
for p = 1:nPages
if ok
endpos = 50*p;
% Id, Rep
expr = '><a href="\/matlabcentral\/answers\/contributors\/(\d+)';
data = regexp(page, expr,'tokens');
if 50*p > totcon; endpos = 50*(p1)+numel(data); end
metainfo(1+(p1)*50:endpos,2) = [data{:}];
% Nickname
expr = ['"Reputation: (\d+)">([\w\ ' reshape([repmat(92,1,137);33:59,61:64,91:97,123:126,161:255],1,[]) ']+)</a></h2>'];
data = regexp(page, expr,'tokens');
metainfo(1+(p1)*50:endpos,[4,3]) = cat(1,data{:});
% Qcount, Ans, Acc
data = regexp(page, '<span >(\d+)</span>[Az<>"\s\/]+','tokens');
metainfo(1+(p1)*50:endpos,5:7) = reshape(cat(1,data{:}),3,[]).';
else
error('Metainfo import stopped. \nCannot read ".../contributors?page=%d"',p)
end
[page, ok] = urlread([url sprintf('%d',p+1)]);
end
</pre>
<pre class="languagematlab">% Convert to doubles
metainfo(:,[2,4:7]) = cellfun(@str2double,metainfo(:,[2,4:7]),'un',false);
</pre>
<pre class="languagematlab">elapsedTime = toc;
</pre>Oleg Komarovhttps://ch.mathworks.com/matlabcentral/profile/authors/1886545olegkomarovtag:ch.mathworks.com,2005:Question/36099820171012T14:19:19Z20171019T09:59:03ZHow to smooth edges of polygons?<p>I created a image (uint8) with multiple filled polygons. First, I used the vision.ShapeInserter with 'Antialiasing' but this was not enough. Also insertShape + 'SmoothEdges' produced insufficient smooth edges. Are there any other ways how I can fix that?</p><p>Looking forward to your suggestions. Thanks!</p>m975https://ch.mathworks.com/matlabcentral/profile/authors/5686192m975tag:ch.mathworks.com,2005:Question/36203620171018T22:10:58Z20171019T09:57:32Zsearch for elements of a vector in a matrix<p>I have a matrix A of size Nx2, N is large. I have another vector b of size nx1 and n<<N. I want to filter out those row indices of A, where both columns could contain any 2 elements of b.</p><p>For instance, let</p><pre> A = [1 2;3 4; 5 6]
b = [1,2,5,6]' </pre><p>Then output of method(A,b) should be</p><pre> [1,3]' </pre><p>(i.e. the first and 3rd rows of A contain 2 elements from b, but not the 2nd row.</p><p>I am currently using a combination of ismember and find but seems like ismember is not very efficient because my A, as I said, is very large.</p><p>Thanks in advance!</p>Ashwin Renganathanhttps://ch.mathworks.com/matlabcentral/profile/authors/6229459ashwinrenganathantag:ch.mathworks.com,2005:Question/36211320171019T09:55:19Z20171019T09:55:19ZIs it possible to tell device 2 to shot when Matlab receives a signal from device 1 ? how can I do this ?<p>I have 2 devices ( a kinetic device and a laser ) which have their own software to control the shots but I want to create an interface to control both. I want the laser to shot a few milliseconds after the kinetic device did the reaction.
With other words, when Matlab will receive a trigger from a device, I want to tell to the other device to shot.
Firt of all, I want to know if it's possible to do this with Matlab. If it's possible, can you please tell me more about the toolboxes I need ?</p>sibel dumluhttps://ch.mathworks.com/matlabcentral/profile/authors/11286115sibeldumlutag:ch.mathworks.com,2005:Question/36199920171018T17:33:00Z20171019T09:53:31ZHow can i store data from a loop into different variables? instead of storing in a vector/matrix. I want to use the different z values for something else. Hoping it could be stored into z(1) and z(2) or some sort. Thanks.<p>for i = (1 : 2)
t = rand(1,1);
z = t + 10;
end</p>Juveno Juvenohttps://ch.mathworks.com/matlabcentral/profile/authors/9449969juvenojuvenotag:ch.mathworks.com,2005:Question/36209920171019T08:33:47Z20171019T09:50:49ZMark specific values on a plot!<p>Hi consider the following plot:</p><pre class="languagematlab">x=1:100;
y=600+(1400600).*rand(100,1);
plot(x,y)
</pre><p>How can I mark the y values between 900 and 1100?
Thanks!</p>Panos Alehttps://ch.mathworks.com/matlabcentral/profile/authors/9465902panosaletag:ch.mathworks.com,2005:Question/36207620171019T05:26:33Z20171019T09:49:18ZIs there any way to connect toad for mysql without using database toolbox?<p>connecting the database without using database toolbox</p>Sandeep Kumar Radha Krishnanhttps://ch.mathworks.com/matlabcentral/profile/authors/10046416sandeepkumarradhakrishnantag:ch.mathworks.com,2005:Question/35734120170919T09:45:30Z20171019T09:48:48ZHow to implement this algorithm?<p>I have a doubt in the above code. I want to declare x=x1,x2,x3..x8
But i got an error</p><pre class="languagematlab">clc;
clear all;
close all;
</pre><pre class="languagematlab">x=[0 1 1 0 1 1 0 1];
y=[0 0 0 0 0 0 0 0];
</pre><pre class="languagematlab">for j=1:8
x[j] = [xj:xj+1];
Yj = (xor(yj1,xj)*H);
end
Y
</pre><p>The error was:
Undefined function or variable 'xj'.</p><p>Error in counter1 (line 9)
x=[xj:xj+1];</p><p>>> counter1
Error: File: counter1.m Line: 9 Column: 8
Unbalanced or unexpected parenthesis or bracket.</p>Darsana P Mhttps://ch.mathworks.com/matlabcentral/profile/authors/9051001darsanapmtag:ch.mathworks.com,2005:Question/36209720171019T08:17:21Z20171019T09:48:45ZHow can put the values inside tolerances?<p>Hey everybody. I am trying to put fs1 and As1 values inside the tolerance. When I try it just for As1 value it works and it can calculate the residual but together, it cannot stop. Is it about data or is there something wrong about loops. I would be appreciated if you would help. Thanks!</p><pre class="languagematlab">ms=1;
msksi=0.013;
Vs1=5.5;
</pre><pre class="languagematlab">As1=0.05:0.005:1.05;
fs1=0.5:0.005:1.5;
loop=0;
</pre><pre class="languagematlab">for i=1:length(As1)
for j=1:length(fs1)
</pre><pre> Us(j)=Vs1.*fs1(j);</pre><pre> [vq]=digdata(Vs1,As1(i));
[vq2]=digdata2(Vs1,As1(i));</pre><pre> As = vq.*Us(j).^2 ./(16.*(pi.^2).*msksi.*fs1(j));
fs= sqrt(1(vq2.*Us(j).^2./(8.*(pi.^2).*ms.*As1(i))));</pre><pre> res1=As1(i)As;
res2=fs1(j)fs;</pre><pre> if abs(res1)<0.01 && abs(res2)<0.01
As1(i)=As;
fs1(j)=fs;
Us(j)=Vs1.*fs1(j);
break </pre><pre> end</pre><pre class="languagematlab">% loop=loop+1
</pre><pre> end</pre><pre> loop=loop+1 </pre><pre> end</pre><p>and this is the digdata function which is same with digdata2 except the datas.</p><pre class="languagematlab">function [ vq ] = digdata( Vs1, As1)
</pre><pre class="languagematlab">load myarray
</pre><pre class="languagematlab">Vs=myarray(:,1); % x
As=myarray(:,2); %y
fc=myarray(:,3); % v
</pre><pre class="languagematlab">vq = griddata(Vs,As,fc,Vs1,As1);
</pre><pre> end</pre><p>Thank you!</p>theinternhttps://ch.mathworks.com/matlabcentral/profile/authors/6659618theinterntag:ch.mathworks.com,2005:Question/36144320171015T19:54:16Z20171019T09:47:08ZHow to get πx (steadystate probabilities of x?in order to plot these equations in MATLAB?<p>Sir,</p><p>I want to plot these attached equations using MATLAB. For plotting these equations, there are three variables. Out of which, I have values of two variables with me. So, I am looking for the value of the third variable 'πx'. How to get the values of πx (also called steady state probability of x). I have attached the screenshot of equations. Actually, if I get the values of πx, I would easily be able to plot the equations in MATLAB. I am unable to get the steadystate probabilities of x.</p><p>Please help</p><p>I have also attached the values of x along with these equations.</p><p>Regards</p><p>Surabhi</p><p>Whatever, the case is either simulation or plotting. I am confused on how to solve to get steadystate probabilities and hence plot the equations.</p>surabhi sachdevahttps://ch.mathworks.com/matlabcentral/profile/authors/7158933surabhisachdevatag:ch.mathworks.com,2005:Question/36211120171019T09:32:44Z20171019T09:45:16ZSimilarity between two 2Dshapes<p>Hello,</p><p>After proceeding to a segmentation of 2 consecutive (in time) images, I obtain 2 BW images, whose white regions are forming some 2Dpatches. I would like to determine the change of position of each patch between the first and second image, and then calculate its velocity, in many points of the patch if possible, since its shape is gonna change a little bit. So, I'd need an algorithm which is able to determine that a given patch in image 1 corresponds to a patch in image 2, by comparing the shape of the contour of the patch.
A difficulty I have to take into account is that it is possible that patches are not complete, cut by the border of the image, and so patch size is gonna be increased/decreased between the 2 images.</p><p>I hope my description of the problem is clear enough, so that someone will able to help me.</p><p>Thanks,</p><p>Sylvain</p>Sylvain Hauserhttps://ch.mathworks.com/matlabcentral/profile/authors/3746856sylvainhausertag:ch.mathworks.com,2005:Question/36205920171019T02:10:33Z20171019T09:41:02ZMy Graphs are looking rather off. I'd like help if possible <img src = "/matlabcentral/answers/uploaded_files/91463/Capture.PNG"><pre class="languagematlab">%% Data
</pre><pre class="languagematlab">% Conversion Factor
D2R = pi/180; % degree to radian
R2D = 180/pi; % radian to degree
</pre><pre class="languagematlab">% Aircraft Data
Wcr = 2600; %% Aircraft Weight, Lbs
Sref = 136.39; %% Aircraft Reference Area, Ft^2
Vcr = 131*1.6878;%% Cruise Velocity, Knots
rho = 1.225; %% Sea Level Density, lbs/Ft^3
</pre><pre class="languagematlab">% Wind Tunnel Model Geometric Data
Sw = 136.9; %% Wing Area, Ft^2
Cbar = 0.27; % MAC, Ft
Lt = 2.22; %% Distance from CG to Tail MAC at hcg = 0.35
St = 27.77; %% Tail Area, Ft^2
hcg = 11.1592; %% CG of Wing+Body (assume same as CG of Aircraft)
</pre><pre class="languagematlab">% Aerodynamic Data
awb = 5.8178*R2D;%% Wingbody lift curve slope, per degree
at = 4.3716*R2D;%% Tail lift curve slope, per degree
e0 = 0.0; %% Downwash Constant, Degree
it = 2:1:2; %% tailincidence angle
deda = 0.3365; %% Downwash Derivative
CMac_wb = 0.0727; %% wingbody moment coefficient about its AC
hn_wb = 4.04; %% wingbody aerodynamic center in %MAC
ae = 4.310*R2D; %% elevator effectiveness coefficient, per degree
</pre><pre class="languagematlab">%% Compute Stability & Control Data
</pre><pre class="languagematlab">% compute aircraft lift curve slope
a = awb*(1+(at/awb)*(St/Sw)*(1deda));
</pre><pre class="languagematlab">% compute total angle of attack & tail angle of attack
alpha_wb = 2:1:10; % wingbody AOA range
alpha = alpha_wb  (at/a)*(St/Sw)*(it+e0); % aircraft AOA
alpha_t = alpha.*(1deda)...
(e0+it)*(1(at/a)*(St/Sw)*(1deda)).*ones(size(alpha)); % tail AOA
</pre><pre class="languagematlab">% compute Lift & Moment about CG from Wing+Body
CL_wb = awb.*alpha_wb
CM_wb = CMac_wb.*ones(size(alpha_wb)) + CL_wb.*(hcghn_wb);
</pre><pre class="languagematlab">% compute Lift & Moment about CG from Tail
CL_t = at.*(alpha_t)
VH = (Lt/Cbar)*(St/Sw);
VHbar = VH + (hcghn_wb)*(St/Sw);
CM_t = VH.*CL_t;
</pre><pre class="languagematlab">% compute total aircraft lift & moment about CG
CL = CL_wb + (St/Sw)*CL_t
CM = CM_wb + CM_t;
</pre><pre class="languagematlab">% compute Neutral Point Location
hn = hn_wb + (at/a)*(VHbar)*(1deda);
Kn = hnhcg;
</pre><pre class="languagematlab">% compute Trim Angle of Attack & Elevator Angle to Trim
CL_trim = Wcr/(0.5*rho*Vcr*Vcr*Sref);
CM0 = CMac_wb + at*VHbar*(e0+it)*(1(at/a)*(St/Sw)*(1deda));
CM_alpha = a*(hcghn_wb)at*VHbar*(1deda);
</pre><pre class="languagematlab">CL_de = ae*(St/Sw);
CM_de = ae*VHbar + CL_de*(hcghn_wb);
</pre><pre class="languagematlab">dumY = [CL_trim;CM0];
dumM = [a CL_de;CM_alpha CM_de];
X = inv(dumM)*dumY;
aoa_trim = X(1,1);
delE_trim = X(2,1);
</pre><pre class="languagematlab">%% Draw Figures
</pre><pre class="languagematlab">figure(1)
plot(CM_wb,alpha,CM_t,alpha,CM,alpha);
grid, axis equal
title('Angle of Attack Vs CM')
xlabel('CM_{wb] CM_t CM [DEG]')
ylabel('\alpha [DEG]')
legend('CM_wb','CM_t','CM')
</pre><pre class="languagematlab">figure(2)
plot(CM,alpha);
grid, axis equal
title('Angle of Attack Vs CM')
xlabel('CM [DEG]')
ylabel('\alpha [DEG]')
legend('CM 2','CM 1','CM 0','CM 1','CM 2')
</pre>Brandon Kammerhttps://ch.mathworks.com/matlabcentral/profile/authors/3116947brandonkammertag:ch.mathworks.com,2005:Question/36150020171016T08:20:29Z20171019T09:40:42ZMatlab Coder, Cfunction return type<p>What determines the return of a parameter when generating Ccode from a function?
In which case is the parameter returned by value (as the cfunction's value) and in which
case is it returned in the parameter list?
How can I ensure that the generated cfunction is alwasy of type void()?
Thanks for helping</p>Christian Steinebachhttps://ch.mathworks.com/matlabcentral/profile/authors/11235132christiansteinebachtag:ch.mathworks.com,2005:Question/36167020171017T05:58:17Z20171019T09:36:03ZProblem with second axis in subplot<p>Hi all!
I plot in a loop several graphs in the same subplot. Now I need a second x axis in the subplot.</p><pre class="languagematlab">figure(1)
HandleP1 = subplot(2, 2, 1, 'Parent', p);
hold on;
plot(n, CH2VS)
ax1 = gca % current axes
ax1.Visible = 'off'; %just to see is the second axis is hidden anywhere
ac12 = axes('Position',ax1.Position,'XAxisLocation','top','YAxisLocation','right','Color','none');
ax12 = gca;
ax12.Visible = 'on';
ax12pos = ax1.Position;
ax12.XLim = ax1.XLim;
</pre><p>In my opinion, these few lines should do the trick, with the second x axis on top of the subplot. But the axis is simply not visible.</p><p>Whats wrong?</p><p>Best regards,
Thomas</p>Thomas Schaeferhttps://ch.mathworks.com/matlabcentral/profile/authors/380539thomasschaefertag:ch.mathworks.com,2005:Question/36208620171019T07:26:41Z20171019T09:29:25ZHow to open tiff stack images in for loop<p>I have a folder F. Under that folder, I have 20 multipage stack .tiff image.</p><p>Each image A in the folder F is a stack of 50images and I need to average those 50images to get only one image B and do the average over the rows of image B then save the mean in an excel file.
Here is my code</p><pre> myexcel = 'F\interference2.xlsx';
out = zeros(1280,20);
for k = 1:20
fname = ['F\image',num2str(k),'.tiff'];
info = imfinfo(fname);
num_images = numel(info); %50images
Z = zeros(1024,1280);
for jj = 1:num_images
Z = Z + double(imread(fname, jj, 'Info', info)); %sum of the 50images
end
avrg = mean(Z/50); %average
out(:,k) = avrg; % store a column in a matrix out
end
xlswrite(myexcel ,out)</pre><p>It always gives an error:
Error using imfinfo (line 100)
Unable to open file "F\image1.tiff"
for reading.</p><p>Error in interf (line 13)
info = imfinfo(fname);</p><p>Thanks for your help.</p>Ratsimandresy Dinahttps://ch.mathworks.com/matlabcentral/profile/authors/10273161ratsimandresydinatag:ch.mathworks.com,2005:Question/36196120171018T13:32:26Z20171019T09:28:52Zcorr2 on simulink don't code genaration<p>The function 'corr2' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.</p><p>what function can replace this function on the simulink simulation?</p>tsai kai shunghttps://ch.mathworks.com/matlabcentral/profile/authors/8441845tsaikaishungtag:ch.mathworks.com,2005:Question/36190420171018T08:03:06Z20171019T09:28:45ZMerging the content of two tables<p>I have two tables <tt>Ta</tt> and <tt>Tb</tt> that have different number of rows and different number of columns. The content is all <i>cell text</i>, but maybe in the future it could also contain <i>cell number</i>.</p><p>.</p><p>I want to merge the content of these tables together under the following set of rules:</p><ul><li>Take the value of <tt>Ta(i,j)</tt> if <tt>Tb(i*,j*)</tt> is empty and vice versa.</li></ul><ul><li>If both are available, then take the value of <tt>Ta(i,j)</tt> (or optionally, check whether they are the same).</li></ul><p>.</p><p>The <b>tricky</b> part however is that <i>we do not have unique row keys</i>, we only have <i>unique column keys</i>. Note above that I make a distinction between <tt>i*</tt> and <tt>i</tt>. The reason is that the row in <tt>Ta</tt> can be at a different index than <tt>Tb</tt>, same holds for the columns <tt>j*</tt> and <tt>j</tt>. The implications are:</p><ul><li>that we first need to identify which row for <tt>Ta</tt> corresponds to the row of <tt>Tb</tt> and vice versa. We can do this by trying to crossmatch any of the columns that the tables share in common.</li></ul><p>To make it also harder:</p><ul><li>the number of rows are not equal for the tables (sometimes there are rows in <tt>Ta</tt> but not in <tt>Tb</tt> and vice versa).</li></ul><p>.</p><p>How can we merge the content of these two tables together in the most efficient way?</p><p>.</p><p>Example variables to play with:</p><pre class="languagematlab">Ta = cell2table({...
'a1', 'b1', 'c1'; ...
'a2', 'b2', 'c2'}, ...
'VariableNames', {'A','B', 'C'})
</pre><pre class="languagematlab">Tb = cell2table({...
'b2*', 'c2', 'd2'; ...
'b3', 'c3', 'd3'; ...
'b4', 'c4', 'd4'}, ...
'VariableNames', {'B','C', 'D'})
</pre><p>The resulting table <tt>Tc</tt> should be something like this:</p><pre class="languagematlab">Tc = cell2table({...
'a1' 'b1' 'c1' ''; ...
'a2' 'b2' 'c2' 'd2'; ...
'' 'b3' 'c3' 'd3'; ...
'' 'b4' 'c4' 'd4'}, ...
'VariableNames', {'A', 'B','C', 'D'})
</pre>William Schaeferhttps://ch.mathworks.com/matlabcentral/profile/authors/10105993williamschaefertag:ch.mathworks.com,2005:Question/36211020171019T09:25:30Z20171019T09:25:30Zsearch for a string in other file and return new files based on multiple condiion<p>Hi and I hope you can give me some advice or suggestion,</p><p>I have bunch of files and what I would like is to create new files based on a condition. For example my input files are curva_pbc_uof_20150103.txt and
curva_pbc_uof_20150104.txt and condition is in cond.txt file.</p><p>I would like to create new files where fourth column of my files matches conditions, so if I have ABO1 in curva_pbc_uof_20150103.txt and ABO1 in cond.txt, I should keep those
rows, and in addition only those rows where the last column is equal to C. All other rows should be neglected.</p><p>Thanks a lot!</p>sensationhttps://ch.mathworks.com/matlabcentral/profile/authors/6595643sensationtag:ch.mathworks.com,2005:Question/36060720171010T13:50:32Z20171019T09:23:52ZNot same fprintf MATLAB and Linux Console<p>Hello everybody,</p><p>I am trying to catch an error and I have made the following code in Matlab:</p><pre class="languagematlab">catch ME
</pre><pre> % Some error occurred if you get here.
errorMessage1 = sprintf('Error in function %s()\n',ME.stack.name);
errorMessage2 = sprintf('Error in line %d\n',ME.stack(1).line);
errorMessage3 = sprintf('Error %s()\n',ME.message);
fprintf(2,'\n');
fprintf(2,'%s\n', errorMessage1);
fprintf(2,'\n');
fprintf(2,'%s\n', errorMessage2);
fprintf(2,'\n');
fprintf(2,'%s\n', errorMessage3);</pre><p>The output of Matlab is the following one:</p><p>Error in hello()</p><p>Error in line 386</p><p>Error Index exceeds matrix dimensions.()</p><p>But, when I execute matlab from de Linux console:</p><p>./matlab < hello.m</p><p>I just get this output:</p><p>Index exceeds matrix dimensions</p><p>I cannot see the line or the .m I am running.</p><p>What kind of problem is this?</p><p>Thanks in advance,</p><p>Javi</p>Javier Naranjohttps://ch.mathworks.com/matlabcentral/profile/authors/10244660javiernaranjotag:ch.mathworks.com,2005:Question/36192820171018T09:58:13Z20171019T09:21:30ZMatlab Engine  passing strings giving invalid characters<p>Hi,
I am writing an Engine application in C, which will be standalone eventually, but I would also like to call the routines via a mex interface if possible. So, at the moment I have a rather convoluted process of a mex file creating a separate instance of the Matlab engine, which I want to talk to (eventually this will be multiple engines via MPI). I'm doing this using Matlab coder.</p><p>So, I have the test code below which is trying to open a new engine from a mex file and talk to it...</p><pre class="languagematlab">function outp = engTest()
</pre><pre class="languagematlab">%Build with.... codegen engTest o engTest_mex
</pre><pre class="languagematlab">params = [1, 2, 3, 4, 5, 6, 7, 8];
paramsLen = 8;
funName = 'total = debugMfile(params,bulk_in,bulk_out,contrast);';
pathCall = 'cd(''/home/arwel/Documents/coding/cevalTests/mlEng'');';
bulkIn = 2.073e6;
bulkOut = 6.35e6;
contrast = 1.0;
</pre><pre class="languagematlab">path = '/home/arwel/Documents/coding/cevalTests/mlEng';
</pre><pre class="languagematlab">incPath1 = '/usr/local/MATLAB/R2015b/extern/include';
incPath2 = '/usr/include/openmpi';
</pre><pre class="languagematlab">linkPath1 = '/usr/local/MATLAB/R2015b/bin/glnxa64';
linkFile1 = 'libeng.so';
linkFile2 = 'libmx.so';
</pre><pre class="languagematlab">source1 = 'matlabCallFun.c';
source2 = 'matlabEngine_demo.h';
</pre><pre class="languagematlab">libPriority = '';
libPreCompiled = true;
libLinkOnly = true;
%libName = 'LinkObj.lib';
%libPath = 'c:\Link_Objects';
%coder.updateBuildInfo('addLinkObjects', libName, libPath, ...
%libPriority, libPreCompiled, libLinkOnly);
</pre><pre class="languagematlab">%coder.updateBuildInfo('addSourceFiles',filename)
coder.cinclude(source2);
coder.updateBuildInfo('addSourceFiles',source1);
coder.updateBuildInfo('addSourcePaths',path);
coder.updateBuildInfo('addIncludePaths',incPath1);
coder.updateBuildInfo('addIncludePaths',incPath2);
coder.updateBuildInfo('addLinkObjects',linkFile1,linkPath1,libPriority,libPreCompiled,libLinkOnly);
coder.updateBuildInfo('addLinkObjects',linkFile2,linkPath1,libPriority,libPreCompiled,libLinkOnly);
</pre><pre class="languagematlab">outp = zeros(2,3);
</pre><pre class="languagematlab">%matlabCallFun(params, paramsLen, funName, pathCall, bulkIn, bulkOut, contrast, s);
coder.ceval('matlabCallFun', params, paramsLen, funName, pathCall, bulkIn, bulkOut, contrast, coder.wref(outp));
</pre><pre class="languagematlab">end
</pre><p>and matlabCallFun.c as follows.....</p><pre> /*
* matlabCallFun.c
*
* Created on: 21 Jul 2017
* Author: arwel
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h></pre><pre> #include "engine.h"</pre><pre> void matlabCallFun(double params[], int arrayLen, char *funName, char *pathCall, double bulkIn, double bulkOut, double contrast, double *sum) {
static Engine *ep;
static double engStatus = 0;
mxArray *result = NULL;</pre><pre> mxArray *PARAMS = NULL;
mxArray *BULKIN = NULL;
mxArray *BULKOUT = NULL;
mxArray *CONTRAST = NULL;
mxArray *FNAME = mxCreateString(funName);
double *s;</pre><pre> if(engStatus == 0) {
ep = engOpen("");
if(ep==0) {
printf("Connecton to Matlab Engine failed\n");
}
else {
printf("Connecton to Matlab Engine succeeded!\n");
engEvalString(ep,(void *)pathCall);
engStatus = 1;
}
}</pre><pre> PARAMS = mxCreateDoubleMatrix(1,arrayLen,mxREAL);
memcpy((void *)mxGetPr(PARAMS), (void *)params, arrayLen*sizeof(double));
engPutVariable(ep,"params",PARAMS);</pre><pre> BULKIN = mxCreateDoubleMatrix(1,1,mxREAL);
memcpy((void *)mxGetPr(BULKIN), &bulkIn, 1*sizeof(double));
engPutVariable(ep,"bulk_in",BULKIN);</pre><pre> BULKOUT = mxCreateDoubleMatrix(1,1,mxREAL);
memcpy((void *)mxGetPr(BULKOUT), &bulkOut, 1*sizeof(double));
engPutVariable(ep,"bulk_out",BULKOUT);</pre><pre> CONTRAST = mxCreateDoubleMatrix(1,1,mxREAL);
memcpy((void *)mxGetPr(CONTRAST), &contrast, 1*sizeof(double));
engPutVariable(ep,"contrast",BULKOUT);</pre><pre> engEvalString(ep,(void *)funName);</pre><pre> result = engGetVariable(ep,"total");
s = (double *)mxGetData(result);</pre><pre> memcpy(sum, s, 8*sizeof(double));</pre><pre> engClose(ep);</pre><pre class="languagematlab">}
</pre><p>When I compile this, and try to run</p><pre class="languagematlab">codegen engTest o engTest_mex
y = engTest_mex
</pre><pre> I get a seg fault, and the following in the relevant terminal window....</pre><pre class="languagematlab">Connecton to Matlab Engine succeeded!
cd('/home/arwel/Documents/coding/cevalTests/mlEng');7

Error: The input character is not valid in MATLAB statements or expressions.
</pre><pre> total = debugMfile(params,bulk_in,bulk_out,contrast);,Y��ǂ���Z

Error: The input character is not valid in MATLAB statements or expressions.</pre><p>What am I missing here?</p><p>Cheers,</p><p>Arwel</p><p>p.s.
The fun being called is....</p><pre class="languagematlab">function total = debugMfile(params,bulk_in,bulk_out,contrast)
</pre><pre class="languagematlab">s = sum(params);
total = [s bulk_out bulk_in ; 4 5 6];
save debugMfileVars.mat
</pre><pre class="languagematlab">end
</pre>Arwelhttps://ch.mathworks.com/matlabcentral/profile/authors/1788146arweltag:ch.mathworks.com,2005:Question/36210520171019T09:02:23Z20171019T09:18:44Zhow to give temperature setpoint to speed controller ?<p>hello friends.
I need to control the speed of compressor to make the cabinet temperature to meet my set point temperature.
I am confusing how to make my temperature error (cabinet temp  setpoint temp) to give as input to BLDC motor.</p><p>Thanks to the responds.</p>VAMSI KRISHNA THANIKANTIhttps://ch.mathworks.com/matlabcentral/profile/authors/8668617vamsikrishnathanikantitag:ch.mathworks.com,2005:Question/36024320171008T12:49:34Z20171019T09:14:25ZHow can I call MATLAB object's method from C++?<p>Hi</p><p>Using bellow command we can easily call a function(here "foo.m") which was wrote in MATLAB from C++.</p><pre class="languagematlab">mexCallMATLAB(nlhs, plhs, nrhs, prhs, "foo")
</pre><p>But what if "foo" is a method of a class?</p><pre class="languagematlab">classdef Foo < handle
...
function out = foo(obj, in)
end
end
</pre><p>Is there any straightforward or trick to call member function from C++?</p>Bonje Firhttps://ch.mathworks.com/matlabcentral/profile/authors/9678898bonjefirtag:ch.mathworks.com,2005:Question/36210920171019T09:13:43Z20171019T09:14:12ZError starting parallel pool<p>I'm using MATLAB 2014b on Windows 7. Typing ver shows I have installed Parallel Computing Toolbox, but when I type</p><pre class="languagematlab">matlabpool open local 2
</pre><p>it throws the following error:</p><img src = "/matlabcentral/answers/uploaded_files/91514/Captura.PNG"><p>then, if I validate the profile 'local' in Cluster Profile Manager, it throws the following comment:</p><img src = "/matlabcentral/answers/uploaded_files/91515/Captura.PNG"><p>I would like to know the cause of this issue. Thanks in advance.</p>E. Valerohttps://ch.mathworks.com/matlabcentral/profile/authors/5844467evalerotag:ch.mathworks.com,2005:Question/36166820171017T05:52:10Z20171019T09:13:24ZHow to write image <pre class="languagematlab">sim =reshape(sim,row,col,3);
gim =reshape(gim,row,col);
figure,
subplot(2,2,2),imshow(gim,[]),title('titl');
subplot(2,2,3),imshow(sim,[]),title('titl');
</pre>Ajay kumarhttps://ch.mathworks.com/matlabcentral/profile/authors/2832012ajaykumartag:ch.mathworks.com,2005:Question/36137820171015T00:05:43Z20171019T09:13:13ZCan't run findpeaks on Matab R2017b on Linux<p>I was previously able to run the findpeaks function on my Linux computer using Matlab R2017a. I upgraded to Matlab R2017b, but can no longer run the function, as I get this error message instead:</p><pre class="languagematlab">Can't load '/usr/local/MATLAB/R2017b/bin/glnxa64/libmwdastudio.so':
/usr/local/MATLAB/R2017b/sys/jxbrowser/glnxa64/xulrunner/xulrunnerlinux64/libnssutil3.so:
version `NSSUTIL_3.12.5' not found (required by
/usr/local/MATLAB/R2017b/bin/glnxa64/libQt5WebEngineCore.so.5)
</pre><p>How can I fix this problem?</p>ervinshiznithttps://ch.mathworks.com/matlabcentral/profile/authors/6763377ervinshiznittag:ch.mathworks.com,2005:Question/32472820170213T09:12:46Z20171019T09:12:58ZHosttoTarget communication suddenly dropped.<p>Hello,</p><p>I recently bumped into a problem that I can not solve or figure out. This involves MATLAB 2016b and I am using Simulink RealTime Explorer.</p><p>My laptop is connected to a switch via an ethernet cable. The target computer (the xPC) is also connected to this switch via an ethernet cable. Up until last thursday I could connect to this target computer but now, out of the blue, it simple says " 'TargetPC1' Unable to connect. Check communication settings ".</p><p>The IPAd, Subnet mask, Port and the Gateway have not changed, the boot CD is still inside. I am well aware of the "Graphic Bug" regarding 2016b when building models but that is no the problem.</p><p>I tried changing the switch and ehternet cables but it still can not connect. Have you seen this problem before?</p><p>Thanks in advance!</p>Hendric Kjellströmhttps://ch.mathworks.com/matlabcentral/profile/authors/9473179hendrickjellstromtag:ch.mathworks.com,2005:Question/36210820171019T09:12:08Z20171019T09:12:08ZHelp in making a time recorder<p>Hi there
recently I was working on creating something like stopwatch, that works in gui. I tried to make a start button that when ever the user click it will start to measure the time and when the user reclick it it saves the time value to X matrix and start over again till the user second click, it saves the second value and start the 3rd count...etc. In the end there is another finish button that will end the function of the start button, and create a table of collected data.</p><p>but it is not working, I am new to gui and I am not understanding much in it.</p><p>I wonder if someone can help create such code, and Thanks in advance.</p>Abdullah Azzamhttps://ch.mathworks.com/matlabcentral/profile/authors/7028962abdullahazzamtag:ch.mathworks.com,2005:Question/36149220171016T06:57:47Z20171019T09:07:43ZGetting MD5 hash of files with "bad" names (Windows, NTFS)<p>I tryed several variants of getting MD5 hash of files with "bad" names
(e.g. 'C:\wrongname.' (with trailing dots); 'C:\wrongname ' (with trailing spaces); (path)names with accents like 'é', 'é' which occur in French, German, Hungarian; containing various forms of dashes (–) etc.).</p><p>None is working, except Var5, but is <b>too slow</b> (calculates a 10Mb file within 10 min).</p><p>Can you suggest any working variant, or how to speed up Var 5?</p><p>OS: Windows 10, File system: NTFS, Matlab 2015a</p><p>% Var 1 </p><pre class="languagematlab">% dirinfo(i).name  is string containing full pathname (e.g. 'C:\myfolder\myfile.ext')
</pre><pre class="languagematlab">Opt.Format = 'HEX'; Opt.Method = 'MD5'; Opt.Input='file';
hash(i) = DataHash(['\\?\' dirinfo(i).name], Opt); % ERROR  not working with "bad" names
% DataHash.m  https://www.mathworks.com/matlabcentral/fileexchange/31272datahash
</pre><p>%Var 2 </p><pre class="languagematlab">hash(i)=mMD5(['\\?\' dirinfo(i).name]); % fast, works on 'C:\wrongname.' (with ending dots), 'C:\wrongname ' (with ending spaces), but do NOT works with file names (or pathes) with accents like 'é', é'
% (mMD5.c, see https://www.mathworks.com/matlabcentral/fileexchange/7919md5inmatlab)
</pre><p>% Var 3 </p><pre class="languagematlab">mddigest = java.security.MessageDigest.getInstance('MD5');
bufsize = 8192;
[fid,errmsg] = fopen(['\\?\' dirinfo(i).name]); % ERROR here  matlab fopen don't understand "bad" names
if fid>=3 % if success
while ~feof(fid)
[currData,len] = fread(fid, bufsize, '*uint8');
if ~isempty(currData)
mddigest.update(currData, 0, len);
end
end
fclose(fid);
hash(i) = reshape(dec2hex(typecast(mddigest.digest(),'uint8'))',1,[]);
else
disp('can't open file');
end
</pre><p>% Var 4 </p><pre class="languagematlab">file = java.io.File(['\\?\' dirinfo(i).name]);
digestream = java.security.DigestInputStream(file,mddigest);
file_bytes = typecast(org.apache.commons.io.FileUtils.readFileToByteArray(file),'uint8'); % ERROR: out of memory if BIG file
if ~isempty(file_bytes)
mddigest.update(file_bytes, 0, numel(file_bytes));
end
hash(i) = reshape(dec2hex(typecast(mddigest.digest(),'uint8'))',1,[]);
</pre><p>% Var 5 </p><pre> mddigest = java.security.MessageDigest.getInstance('MD5');
filestream = java.io.FileInputStream(java.io.File(['\\?\' dirinfo(i).name]));
digestream = java.security.DigestInputStream(filestream,mddigest);
while(digestream.read() ~= 1), end % TOO LONG  never goes out this cycle
hash(i)=reshape(dec2hex(typecast(mddigest.digest(),'uint8'))',1,[]);</pre>bbb_bbbhttps://ch.mathworks.com/matlabcentral/profile/authors/8958491bbb_bbbtag:ch.mathworks.com,2005:Question/36210720171019T09:05:55Z20171019T09:05:55ZHow can I receive data from python over UDP<p>I'm new to Python and Matlab. I managed to write a C program that sends datagrams consisting of strings or numbers to Matlab over UDP but I'm struggling to get it to work with Python. Even just sending a single integer. I can receive a char! This probably belongs more on a Python forum but finding Matlab users there will probably be harder than finding Python users here!</p><p>If I send a number from 0 to 20. Matlab always captures it as 10.</p><p>I've tried converting to a string using str before sending, and I've tried packing it using struct.pack('!i', i) where i is the integer being sent as part of a loop.
In matlab I've tried using fread(fd, 1) and (fd, 1, 'int'). The latter results in an 'unsuccesful read' warning. I'm missing something really basic but I just can't figure it out. Python is really difficult to get to grips with coming from C but I've had an even bigger struggle with Matlab.</p>alidafhttps://ch.mathworks.com/matlabcentral/profile/authors/11167480alidaftag:ch.mathworks.com,2005:Question/35731120170919T06:55:16Z20171019T09:04:35ZHow to get the LSB of a number?<p>If suppose the number is 110110, how to get its LSB in matlab?</p>Darsana P Mhttps://ch.mathworks.com/matlabcentral/profile/authors/9051001darsanapmtag:ch.mathworks.com,2005:Question/36210020171019T08:37:25Z20171019T09:02:49ZDifferent answer using inbuilt function and own code for entropy<p>When I use the inbuilt function and my own code for entropy, the answer is different.</p><pre class="languagematlab">E = sum(Rarray(Rarray>0) .* log2(Rarray(Rarray>0)));
E2 = entropy(Rarray);
</pre><p>Entropy with Writen code = 768.0522</p><p>Entropy wth Function = 1.7366</p>Amy Wonghttps://ch.mathworks.com/matlabcentral/profile/authors/11277673amywongtag:ch.mathworks.com,2005:Question/36181920171017T19:11:20Z20171019T08:59:46ZHow to deal with two vectors as optimization variables<p>Hello everybody!</p><p>Currently, I am working on topology optimization (ground structure method, minimum compliance design) and I coded most of the predefined variables already. Now, that I have to implement the problem formulation for the optimizers e.g. fmincon, fminimax I don't know how... I appreciate any help!</p><p>So this is the problem statement:</p><img src = "/matlabcentral/answers/uploaded_files/91301/problem.JPG"><ul><li>f  nodal force vector (size N)</li><li>u  nodal displacement (size N)</li><li>t  volume of bars/ members (size m)</li><li>K_i  "local" stiffness matrix (size NxN)</li><li>V  target Volume</li><li>m  number of members</li></ul><p>The problem can be further reduced to a minmax formulation:</p><p><b>min(u) max(t) 1/2 * u^T * sum(t_i*K_i) * u  f^T * u</b></p><p>But when I start implementing the problem in Matlab I fail at some point...I tried to use fminimax but as I have to compute the costfunction with predefined variables e.g K_i, f and fminimax needs the costfunction to be depended only on the optimization variable it doesnt work. However, I also want to know the displacements u as well as the volume of the bars at the end...Any suggestions how to solve the problem? Im not a mathematician. Perhaps the problem can be further reduced, differently formulated..</p><p>Thank you  Merci  Muchas Gracias  Danke</p><p>Jan</p>JandEhttps://ch.mathworks.com/matlabcentral/profile/authors/7107563jandetag:ch.mathworks.com,2005:Question/36196220171018T13:33:38Z20171019T08:55:07ZDisplay an image changing its color<p>Hi,</p><p>I want to display a white image during 10 seconds, changing its color to black every 1 second from white to black. My code is as follows:</p><pre class="languagematlab">% Create vector image
img = 255 * ones(1000, 1000, 3, 'uint8');
% Get handle of the image
handle = imshow(img);
% Experiment time = 10 seconds
a = tic;
while toc(a)<10
% Change color to white
handle.CData = 255 * ones(1000, 1000, 3, 'uint8');
% Display image
imshow(img);
b = tic;
% Wait 1 second until the change of color
while toc(b) < 1
end
% Change color to black
handle.CData = 0 * ones(1000, 1000, 3, 'uint8');
% Display image
imshow(img);
end
</pre><p>Sadly, no image is displayed during the 10 second while. The image is only displayed after the loop is over, so no change can be appreciated.</p><p>I would like to know where is my mistake.</p>E. Valerohttps://ch.mathworks.com/matlabcentral/profile/authors/5844467evalerotag:ch.mathworks.com,2005:Question/36193220171018T10:06:25Z20171019T08:54:25ZStrange bug using 'from workspace' block<p>Hello, I am using the 'from workspace' block to load a signal into my matlab model. The signal has 840k samples. I notice that the response of my simulation was different from the code, so when I investigate I noticed that around the 500k samples the samples start to be different than the loaded signal, and it does not matter the time step used.</p><p>the time step is 5e7s. In total, it seems that there are close to 500 samples wrong. I cannot figure out what can be the cause. =S</p>Douglas Pintohttps://ch.mathworks.com/matlabcentral/profile/authors/11147153douglaspintotag:ch.mathworks.com,2005:Question/36111220171013T04:16:53Z20171019T08:50:33ZDifferent wavelet decomposition output matlab and simulink<p>Hi,</p><p>I have built a code that used wavelet decomposition ('wavedec') with 3 levels and sym3 mother wavelet. When I tried to build a model in simulink using the DWT block with symlets, assymetric, and 3 levels selected, the outputs of the transformations are different.</p><p>Please help me figure out why this is or how can I make it the same.</p><p>Thank you.</p>Douglas Pintohttps://ch.mathworks.com/matlabcentral/profile/authors/11147153douglaspintotag:ch.mathworks.com,2005:Question/36190620171018T08:15:36Z20171019T08:50:06ZHow to adjust the ratio to compare the data in two variables?<p>There are two different variables.</p><pre class="languagematlab">A=[107.5383 47.4492 36.4819 26.4964];
B=1.0e+03 * [4.1876 3.5687 3.4444 3.4548];
</pre><p>I want to know the correlation between A and B.</p><p>But, it is too large difference between A and B.</p><p>in that case, how to adjust?</p>Brian Kimhttps://ch.mathworks.com/matlabcentral/profile/authors/8072373briankimtag:ch.mathworks.com,2005:Question/36210320171019T08:49:57Z20171019T08:49:57ZCircular HOG blocks (CHOG) <p>Hi there,</p><p>AM struggling to find a mtlab code on Circular Histograms of Oriented Gradients. I have applied the rectangular Histograms of Oriented Gradients and I want to compare the results with Circular Histograms of Oriented Gradients. Could you pls help about that?</p>Dhurgham Alkarawi https://ch.mathworks.com/matlabcentral/profile/authors/6500027dhurghamalkarawi