https://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2015-08-28T09:48:53Ztag:www.mathworks.com,2005:Question/2370242015-08-27T14:18:47Z2015-08-28T09:48:53Zjoin each elements of 2 matrices<p>Hi
I have 2 matrices of this type, A=[1 2 3 3 4 5 6 7 8 9 10 11 12] and B=[ 2012 2013 2014 2015]. I would like to have a matrix C of this type C=[1-2012 2-2012 3-2012 4-2012 5-2012 6-2012 7-2012 8-2012 9-2012 10-2012 11-2012 12-2012; 1-2013 2-2013 3-2013 4-2013 ...] and so on.
Basically matrix A are the number of the months and B are simple years.
Any help is much appreciated. Thank a lot in advance</p>andtonhttps://www.mathworks.com/matlabcentral/profile/authors/4766441-andtontag:www.mathworks.com,2005:Question/2373732015-08-28T09:33:44Z2015-08-28T09:47:53ZA=[6 6;7 8;0 9;9 10] B=[6 6;0 9] how to find Matrix C with rows not in B but in A?<pre class="language-matlab">A=[6 6;7 8;0 9;9 10]
B=[6 6;0 9]
</pre><p>how to find Matrix C with row not in B but in A?</p>SRI SINDHU S Phttps://www.mathworks.com/matlabcentral/profile/authors/6730377-sri-sindhu-s-ptag:www.mathworks.com,2005:Question/2370182015-08-27T14:14:44Z2015-08-28T09:40:19ZCall a Fortran code in Matlab to get the result which I will use it in Matlab code<p>I have a Fortran code and I want to run it in MATLAB, By this I will get the output from Fortran code and will use it in Matlab code. I was trying with system command but it is only opening Fortran interface with code not running.Please help me to do this.</p>Sumit Palhttps://www.mathworks.com/matlabcentral/profile/authors/6814463-sumit-paltag:www.mathworks.com,2005:Question/2371152015-08-27T22:54:03Z2015-08-28T09:32:48ZHow can I get a simulink model to execute in real-time?<p>I'm trying to get a Simulink model of a quadrotor and controller to accept inputs and run at real-time speed. My goal is to have this low-level controller interface with a higher level controller in Python</p>Ryanhttps://www.mathworks.com/matlabcentral/profile/authors/4349122-ryantag:www.mathworks.com,2005:Question/2365132015-08-26T07:20:44Z2015-08-28T09:29:28Zhow to convert a matrix with values in decimal point to an image<p>I want to convert a matrix having decimal(.) values with in range of 0-255 into an image. e.g the matrix contains the values like [ 122.0456 33.6785 47.0048; 233.8765 121.6743 45.6780].
floor/ceil/round will round off the decimal values . But i want to retrieve the same matrix with decimal points after retrieving the matrix from image.
please help</p>studentambitioushttps://www.mathworks.com/matlabcentral/profile/authors/6818953-studentambitioustag:www.mathworks.com,2005:Question/2373712015-08-28T09:23:38Z2015-08-28T09:23:38ZHow to change the number of input/output-terminals based on mask parameter<p>I’m now writing a custom driver for Simulink Real-time and have a question about how to change the number of input/output-terminals. I want to change the number of the terminals by setting the mask parameter “channel” like pre-installed drivers, e.g. MM-32 Diamond Analog Input or PCI-6621 National Instr. Analog Input.</p><p>I started to write the driver using “xpcdrivertool” and added initialization function (below) using these pre-installed drivers as examples.</p><pre class="language-matlab">function [maskdisplay] = init(channel)
</pre><pre class="language-matlab">maskdisplay = sprintf( 'disp(''Interface Baord'');' );
for i=1:length(channel)
maskdisplay = sprintf('%s port_label(''output'', %d, ''%d'');', maskdisplay, i, channel(i) );
end
</pre><p>In the mask editor of the driver block, I added ‘channel’ parameter and wrote an initialization command as follows.</p><pre class="language-matlab">[maskDisplay] = init(channel);
set_param(gcb, 'MaskDisplay', maskDisplay);
</pre><p>Also, I’m changing the number of terminals in the initialization function in C code as follows.</p><pre class="language-matlab">if (!ssSetNumOutputPorts(S, number_of_channels)) return;
for (i = 0; i < number_of_channels; i++) {
ssSetOutputPortWidth(S, i, 1);
}
</pre><p>However, the number of terminals does not change in the block diagram.
Can someone please help me out?</p>Teppei Tsujitahttps://www.mathworks.com/matlabcentral/profile/authors/6687177-teppei-tsujitatag:www.mathworks.com,2005:Question/2372632015-08-28T06:37:40Z2015-08-28T09:21:48ZHow to convert R G B ( separate ) into color image in simulink?<p>I'm tried many times in simulink but i could't find the block. plz anyone tell me</p>DINESH RAJA Phttps://www.mathworks.com/matlabcentral/profile/authors/6831428-dinesh-raja-ptag:www.mathworks.com,2005:Question/2362062015-08-25T08:57:24Z2015-08-28T09:19:00ZConvert Matlab script in C++ ?<p>Hello,</p><p>I have a Matlab script that I would like to convert in C++, is it possible to do that with Matlab Coder ? Because, when I add my script as an Entry-Point File, I get this message: "All Entry_Point Files must be functions".</p><p>Can Matlab Compiler do the conversion from the script to C++ ?</p><p>Thank you in advance for your answer.</p><p>Fanta C.</p>Fanta Camarahttps://www.mathworks.com/matlabcentral/profile/authors/6812316-fanta-camaratag:www.mathworks.com,2005:Question/2367252015-08-26T19:01:49Z2015-08-28T09:17:15ZI want to display image from cell array .<p>I have divided my image into sub-images and have stored them in a cell array.
And processed them , now I want to display them as one single entity. Any suggestions would help me.</p>Pradeep Gowdahttps://www.mathworks.com/matlabcentral/profile/authors/5655810-pradeep-gowdatag:www.mathworks.com,2005:Question/2368942015-08-27T09:08:11Z2015-08-28T09:11:51ZHandling large data set in matlab<p>Hi
I have an fmri dataset of 510000(voxels) rows and 150 columns(timepoints) in an excel file.How to import this large data to matlab.Please help.</p>Vasuki Prathyushahttps://www.mathworks.com/matlabcentral/profile/authors/6825656-vasuki-prathyushatag:www.mathworks.com,2005:Question/2349792015-08-21T07:24:11Z2015-08-28T09:09:43Zdoubt regarding bwconncomp example.<p>This is a small doubt.....I'm stuck in the second example given for <tt>bwconncomp</tt> by Mathworks.
This example removes the group of pixels having largest pixels connected (in an 8 connected neighbourhood):</p><pre class="language-matlab">BW = imread('text.png');
imshow(BW);
CC = bwconncomp(BW);
numPixels = cellfun(@numel,CC.PixelIdxList);
[biggest,idx] = max(numPixels);
BW(CC.PixelIdxList{idx}) = 0;
figure, imshow(BW);
</pre><p>I want to change the code to erase groups of pixels which have between 20 to 70 connected pixels (in their 8 connected neighbourhood). How can I do this?</p><p>If I do:</p><pre class="language-matlab">idx = numPixels < 70;
</pre><p>I get an error saying : " <i>Maximum variable size allowed by the program is exceeded</i>."</p>Meghana Dineshhttps://www.mathworks.com/matlabcentral/profile/authors/5488039-meghana-dineshtag:www.mathworks.com,2005:Question/2372502015-08-28T06:23:39Z2015-08-28T09:09:16ZHow to implement a pipe function as in F# (|>) or in R (%>%)<p>I use R from time to another and really love the functionality to have the pipe function in R. Has there been any thoughts on implementing something similar in Matlab?</p><p>The pipe function lets you pass an intermediate result onto the next function. For example if you have something like</p><pre class="language-matlab">logical(reshape(repmat(A,1,4),n,1))
</pre><p>You could instead write</p><pre class="language-matlab">A %>% repmat(1,4) %>% reshape(n,1) %>% logical()
</pre><p>which is much easier to read.</p><p>Is there any way to do this in Matlab and has anyone discussed that this could be included?</p>Benjaminhttps://www.mathworks.com/matlabcentral/profile/authors/1771472-benjamintag:www.mathworks.com,2005:Question/2373662015-08-28T09:07:26Z2015-08-28T09:07:26ZMS Excel function TODAY() not updating when opened using MATLAB XLSREAD<p>I use the TODAY() function in an excel worksheet which is accessed using MATLAB (i.e. I don't read the worksheet directly). Now I have to open the excel file just to update the TODAY() function, and this method is a bottleneck in my workflow.</p><p>I know it's possible to set Excel to automatically update cells upon being opened under the calculation tab, but apparently this does not apply to MATLAB (or COM interfaces in general?). Can someone give me an idea of what can be done?</p><p>EDIT: I'm using MATLAB's built in 'xlsread' command</p>Chris Coutinhohttps://www.mathworks.com/matlabcentral/profile/authors/6132885-chris-coutinhotag:www.mathworks.com,2005:Question/2365902015-08-26T09:15:14Z2015-08-28T09:03:21ZHow to write matlab code for following equation using multiobjective genetic algorithm and get the minimized value of 'd' as output ?<img src = "/matlabcentral/answers/uploaded_files/36221/Untitled.png"><p>Using multiobjective optimization solve this function with following:</p><p>The initial population is stated as follows:</p><img src = "/matlabcentral/answers/uploaded_files/36222/Capture.PNG"><p>I am facing problem in executing codes for this question, I have coded as follows:</p><p>I made a filness function "fitfu2" as</p><pre class="language-matlab">function y = fitfu2(N)
%N = 12; % element numbers
j = sqrt(-1);
AF = zeros(1,360);
deg2rad=zeros(1,360);
for theta = 60:360
deg2rad(theta) = (theta*pi)/180;
for k = 1:N-1
for d = 0:0.5:0.5*k
for n=1:N-1
AF(theta) = AF(theta) + exp(j*n*2*pi*d*(cos(deg2rad(theta))));
end
AF(theta)=1+AF(theta);
end
end
end
y = abs(AF(theta));
</pre><p>and then I used following codes to use multiobjective genetic optimization toolbox</p><pre class="language-matlab">N=12; % Number of elements
FitnessFunction = @(d) fitfu2(N);
NumberOfVariables = 11;
options = gaoptimset('PopulationSize',20);
[x,f] = gamultiobj(FitnessFunction,NumberOfVariables,[],[],[],[],2,10,options);
</pre><p>This is executing but I am confused about how to get desired output and I am not getting minimized value of 'd'.</p><p>Actually I want to Optimize this function taking 'd' as a parameter means to minimize the function as well as minimize 'd' and give the minimized value of 'd' at each iteration as optput.</p><p>If there is any Error or wrong coding ,Please Rectify and send me back the rectified codes that will execute and give me desired result.</p>Manish Mathewhttps://www.mathworks.com/matlabcentral/profile/authors/6737032-manish-mathewtag:www.mathworks.com,2005:Question/2373322015-08-28T08:20:25Z2015-08-28T09:00:19ZI want to write a small program...<p>Please help me to write program for following algorithm</p><p>The algorithm for a program is as follows</p><pre> Inputs
a=0; b=5; n=10
f(x)=x^2+54/x</pre><pre> Step 1
x1=a; dx=(b-a)/n; x2=x1+dx; x3=x2+dx;</pre><pre> Step 2
if f(x1)>=f(x2)<=f(x3)
answer is(x1,x3)
else x1=x2; x2=x3, x3=x2+dx;
and go to step 3</pre><pre> Step 3
check if x3<=b
if yes go to step 2
else there is no answer</pre>Maruti Patilhttps://www.mathworks.com/matlabcentral/profile/authors/6282938-maruti-patiltag:www.mathworks.com,2005:Question/2371092015-08-27T21:29:25Z2015-08-28T08:58:09ZHow to find coordinates(x,y) from jpg file <p>How to find coordinates(x,y) from jpg file</p>mahipal komandlahttps://www.mathworks.com/matlabcentral/profile/authors/2628056-mahipal-komandlatag:www.mathworks.com,2005:Question/2373382015-08-28T08:32:40Z2015-08-28T08:49:58ZWhy fmincon gives different objfun values with the same values of variables? <p>Dear all, I am trying to use fmincon to maximize an objective function, which includes a system of odes to be solved. I tried to store the x values (x is a vector of 3 elements) and fval values at every iteration. Below is the part of the message that fmincon gave me:</p><p>Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current step is less than the default value of the step size tolerance and constraints are satisfied to within the default value of the constraint tolerance. <a href = "stopping">criteria details</a></p><pre> x: [4x3 double]
fval: [4x1 double]</pre><pre> iterations: 4
funcCount: 68
constrviolation: 0
stepsize: 2.4333e-10
algorithm: 'interior-point'
firstorderopt: 1.6806e+09
cgiterations: 39
message: 'Local minimum possible. Constraints satisfied.</pre><p>fmincon s...'</p><img src = "/matlabcentral/answers/uploaded_files/36316/output.JPG"><p>>>My question is why the last two values of fval are different while the values of x are identical (shown in the table). I also checked the
intermediate values (values at each funevaluations), and found that the objective function was called for a number of times with the same set of x vales!!!!</p><p>Could anyone please explain the possible reasons??</p><p>Many many thanks in advance.</p><p>Best regards
Mahmudul</p>Mahmudul Hasanhttps://www.mathworks.com/matlabcentral/profile/authors/2554819-mahmudul-hasantag:www.mathworks.com,2005:Question/2372822015-08-28T07:17:39Z2015-08-28T08:44:33Zreason for converting image into double<p>while reading the, why have to convert an image into double format.</p>sandeep kumarhttps://www.mathworks.com/matlabcentral/profile/authors/2289403-sandeep-kumartag:www.mathworks.com,2005:Question/2366202015-08-26T11:01:37Z2015-08-28T08:41:53ZHow to compute a summation of the following equation?<p>I need to compute it dynamically. Please help me out with the code. Please find the attachment....
Thank you</p>shishir kumarhttps://www.mathworks.com/matlabcentral/profile/authors/6323984-shishir-kumartag:www.mathworks.com,2005:Question/2373442015-08-28T08:40:53Z2015-08-28T08:50:56ZHow can i use MLToolbox MeteoLab?<p>Dear All,</p><p>I downloaded MLToolbox_R2013 which contains Meteolab according to <a href = "https://meteo.unican.es/trac/MLToolbox/wiki/Installation">https://meteo.unican.es/trac/MLToolbox/wiki/Installation</a></p><p>When I run</p><pre class="language-matlab">>>init
</pre><p>script in MeteoLab toolbox I got the following message:</p><pre class="language-matlab">To save the configuration, remember to save the path
</pre><p>I do not understand what it is mean? When I try load a domain data from Iberia_NCEP by:</p><pre> dmn=readDomain('Iberia_NCEP');</pre><p>I got the folowing error:</p><pre class="language-matlab">Error using getZonePath (line 8)
Directory Iberia_NCEP cannot be found in path Iberia_NCEP nor c:\Users\Beata\Documents\MATLAB \MLToolbox_R2013\MeteoLab/../PatternsData/
</pre><pre> Error in readDomain (line 24)
datCam=getZonePath(fic);</pre><p>Could someone write me what I should to do to use MLToolbox?</p><p>Thank you for your help in advance!</p>Szabó-Takács Beátahttps://www.mathworks.com/matlabcentral/profile/authors/6427862-szabo-takacs-beatatag:www.mathworks.com,2005:Question/2372742015-08-28T07:06:33Z2015-08-28T08:38:08ZIntermittent delay while running Simulink MATLAB Real-Time-Workshop with server license <p>Anyone knows for sure if intermittent delays will occur when using MATLAB with server license while running Real-Time-Workshop (RTW) on Simulink for real-time, hardware-in-the-loop controls?</p><p>I am guessing it's caused by MATLAB when it checks the server (thru network) for licenses for toolboxes, but need to know for sure before dropping the bills for a standalone license.</p><p>Delay messes up my engine speed reading (hardware), which relies on counters from a quadrature encoder (hence time delay messes up the timing of the counter)</p><p>Previously I was running the same setup on an older computer (32-bit, with standalone license) but after migrating to a faster 64-bit PC with a server license, the delay occurs intermittently.</p><p>New computer is using MATLAB R2014B 64-bit, while old one had R2008B 32-bit.</p><p>Could also the migration from 32-bit to 64-bit causes the issue? Or is it issue with the compiler? (Tried different compilers, but it didnt fix it)</p><p><b>just saw that small delays (< 0.5 seconds) occurs more frequently than long delays (3-10 seconds)</b></p><p>Any help is appreciated. Thanks!</p>Mohd Azrin Mohd Zulkeflihttps://www.mathworks.com/matlabcentral/profile/authors/1503575-mohd-azrin-mohd-zulkeflitag:www.mathworks.com,2005:Question/2370722015-08-27T16:23:22Z2015-08-28T08:33:39Z2 differenct size arrays, I want to make the shorter array the same size as the longer by adding Zeros between the indices or the missing numbers and make them the same length<pre class="language-matlab">A=[1:10,1:10]'
B=[2 4 6 8 ; 3 3 3 3]'
</pre><p>The output I am trying to aim for is a matrix same size as A but column 2 has the values of B(:,2) see below</p><pre class="language-matlab">Output=[1:10 ; 0 3 0 3 0 3 0 3 0 0]'
</pre><p>I have tried various loops but I get indicies not same used vertcat to add to B the missing values this does not work either, tried all sorts for eg</p><pre class="language-matlab">for ii= 1:10
if ii~=B(ii,1)
B(ii,1)=vertcat(ii,B(:,1));
B(ii,2)=vertcat(0,B(:,2));
else
B(ii,1)=B(ii,1);
B(ii,2)=B(ii,2);
end
end
</pre>Ranjit Kaurhttps://www.mathworks.com/matlabcentral/profile/authors/6580933-ranjit-kaurtag:www.mathworks.com,2005:Question/2356462015-08-24T06:31:14Z2015-08-28T08:28:10ZStop Itration of a matric when it converges<p>My matrix is iterating with each element using same equation. I want to stop the iteration at convergence. My code (below) is not stopping no matter what. Can someone please help me out?</p><pre class="language-matlab">probability = (ones(1,2048) .* 1/2048);
Tij = sum(StateTransitionfwd);
Tji = sum(StateTransitionbwd);
p = ((Tji .* probability) - (Tij .* probability));
</pre><pre class="language-matlab">threshold = (zeros(1,2048));
old = p;
new = zeros(1,2048);
</pre><pre> while true
p = ((p * StateTransitionbwd) - (Tij .* p));
new = p;</pre><pre> if old-new <= threshold</pre><pre> break
end
old = p;</pre><pre> %old - new = threshold;</pre><pre class="language-matlab">end
</pre>Salman Saeedhttps://www.mathworks.com/matlabcentral/profile/authors/6568223-salman-saeedtag:www.mathworks.com,2005:Question/2373352015-08-28T08:22:26Z2015-08-28T08:33:52Zhow can I process the similarity of two images using jaccard distance in matlab gui? <p>% We compute the intersection of the two lines using the "AND" operator "&".</p><p>handles.intersectImg = intersect(handles.popupmenu1,handles.pushbutton1);</p><p>% We compute the union of the two lines using the "OR" operator "|".</p><p>handles.unionImg = union(handles.popupmenu1,handles.pushbutton1);</p><p>% There is only one pixel that overlaps (intersects)</p><p>handles.numerator = sum(handles.intersectImg(:));</p><p>% There are 5 pixels that are unioned.</p><p>handles.denomenator = sum(handles.unionImg(:));</p><p>handles.jaccardIndex = handles.numerator/handles.denomenator</p><p>% Jaccard distance shows how dis-similar the two line drawings are.</p><p>handles.jaccardDistance = 1 - handles.jaccardIndex</p><p>if (handles.jaccardIndex >=0.5)</p><p>per=100*handles.jaccardIndex;</p><p>%axes(handles.Result);</p><pre> %imshow('Peratusan Persamaan:')</pre><pre> %imshow(per);</pre><pre> %imshow('Betul! Ini bentuk segiempat')</pre><pre> set(handles.pushbutton2, 'String', num2str(per));</pre><pre> %axes(handles.check);</pre><p>else</p><pre> per=100*handles.jaccardIndex;</pre><p>%axes(handles.Result);</p><pre> %imshow('Peratusan Persamaan:')</pre><pre> %imshow(per);</pre><pre> %imshow('Salah! Ini bukan bentuk segiempat')</pre><pre> set(handles.pushbutton2, 'String', num2str(per));</pre><pre> %axes(handles.check);</pre><p>end</p>nisa 123https://www.mathworks.com/matlabcentral/profile/authors/6831193-nisa-123tag:www.mathworks.com,2005:Question/2373332015-08-28T08:20:34Z2015-08-28T09:22:02Za problem with using ps image printed by simulink in my latex file<p><b>I print my simulik model to ps image file.and include it in latex article.</b></p><img src = "/matlabcentral/answers/uploaded_files/36312/%E6%8D%95%E8%8E%B71.PNG"><p><b>and compile latex file to dvi,it's allright.</b></p><img src = "/matlabcentral/answers/uploaded_files/36313/%E6%8D%95%E8%8E%B72.PNG"><p><b>but when I compile dvi to pdf,
there is a big white block covered some words which should been displayed</b></p><img src = "/matlabcentral/answers/uploaded_files/36314/%E6%8D%95%E8%8E%B73.PNG"><p><b>How could I removed the the excess white block off?</b></p>213https://www.mathworks.com/matlabcentral/profile/authors/1788135-213tag:www.mathworks.com,2005:Question/980572010-08-26T22:57:00Z2015-08-28T08:10:03ZHow can I import DIAdem measurement data into MATLAB?<p>I have TDM files which contain measurements taken with National Instruments DIAdem software. I would like to import the data into MATLAB to visualize and post-process the data.</p>MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/2373262015-08-28T08:10:02Z2015-08-28T08:10:02ZClassification Learner - importing character variables?<p>Hello there, I hope someone here can help me with a probably trivial problem. I want to use the Classification Learner App. I have a dataset with a numerical response (years) and a number of character variables as predictors or, if possible, a mix of numerical and character variables as predictors. It seems like the Classification Learner App doesn't recognize character variables and I can't the the app to import my predictor variables.
Does anyone have a solution for this??</p><p>Cheers
Niclas</p>Niclas Scotthttps://www.mathworks.com/matlabcentral/profile/authors/1925799-niclas-scotttag:www.mathworks.com,2005:Question/1599112014-10-24T09:26:20Z2015-08-28T07:59:42ZCould anyone help me with tolerances erroe that I got when I am trying to implement an integration please??<pre class="language-matlab">function RunLogisticOscilFisher
omega=1;
k=10;
N0=1;
A=1;
p0=.1;
tspan=(0:0.01:100);
% Finding the numerical solution for the function using ode45 solver
[t,p]=ode45(@logisticOscilfisher,tspan,p0,[],N0,k,omega);
% Plotting the function with time
figure(1)
plot(t,p)
P = @(T) interp1(t,p,T);
% Finding the integral to get the Fisher Information
f = @(T) ( A*(((N0*sin(omega*T).^2.*(1-2*P(T)./k))+(omega.*cos(omega*T) ) ).^2)./(N0.^2*sin(omega*T).^4.*(P(T)-P(T).^2./k).^2) )
I1=integral( f, 1,10)
I2=integral( f, 1,40,'ArrayValued',true)
I3=integral( f, 1,60,'ArrayValued',true)
I4=integral(f,1,80,'ArrayValued',true)
I5=integral(f,1,100,'ArrayValued',true)
I=[I1./20 I2./40 I3./60 I4./80 I5./100]
R=[20 40 60 80 100];
%Plotting the Fisher Information
figure(2)
plot(R,I);
1;
% function dpdt = logisticOscilfisher(t,p,N0,k,omega)
% dpdt = N0*sin(omega*t)*p*(1-p/k);
% end
</pre>Avan Al-Saffarhttps://www.mathworks.com/matlabcentral/profile/authors/5297065-avan-al-saffartag:www.mathworks.com,2005:Question/2372622015-08-28T06:37:26Z2015-08-28T07:59:23Zplease tell me about image interpolation.<p>i tried imresize function but in that i dint understand</p><p>In some paper, authors used image interpolation by factor alpha to increase or decrease the size of the image. please tell how this this alpha factor used in an image interpolation</p>sandeep kumarhttps://www.mathworks.com/matlabcentral/profile/authors/2289403-sandeep-kumartag:www.mathworks.com,2005:Question/2344482015-08-18T17:13:44Z2015-08-28T07:56:17Zspeed up m-file with mex <p>I find many example of mex, but all of examples I found are that
all of the methods to write code just like C code
and without calling any matlab bulit-in function.
Does m-file can not be transformed to mex file?
I tried to do this, but it present the result that is not successful.</p>Yianhttps://www.mathworks.com/matlabcentral/profile/authors/5309775-yiantag:www.mathworks.com,2005:Question/910362013-10-22T08:55:44Z2015-08-28T07:36:48ZSplit an color image to its 3 RGB channels,<p>Hi,</p><p>How can I split an color image to its 3 RGB channels, like in this link:</p><p><a href = "http://www.originlab.com/www/products/images/ChannelSplit_Merge.png">http://www.originlab.com/www/products/images/ChannelSplit_Merge.png</a></p><p>Thanks</p>huhttps://www.mathworks.com/matlabcentral/profile/authors/4719628-hutag:www.mathworks.com,2005:Question/2373002015-08-28T07:28:40Z2015-08-28T07:28:40ZUsing the Xilinx's system generator within simulink - issue involving gateway out blocks ?<p>I have created a filter in Simulink using Xilinx system generator block-set and was trying to ensure the operation of the filter is correct by using spectrum analysers connected to gateway out blocks at the output of my filter in order to view the frequency spectrum. The result as observed on the spectrum analysers shows a lot of unwanted frequency products. I am 100% sure that these products are not due to the test which I am running on the filter. Is it possible that the gateway out blocks are causing some sort of distortion or re-sampling to the output signal ?</p>D.Clarkhttps://www.mathworks.com/matlabcentral/profile/authors/6831501-d-clarktag:www.mathworks.com,2005:Question/2367742015-08-27T01:35:34Z2015-08-28T07:23:15ZSort a vector in matlab<p>Somebody can help me?
From the routine in Matlab I get a vector whose length can be a number between 0 and 24. The content of this vector are numbers between 0 and 24. However, I have to sort this vector with the next conditions</p><p>1. The content must be equal to index of the sorted vector.
2. If in the content of the vector, a number doesn't exist must be equal to NaN</p><p>For example</p><p>Index Content</p><ul><li>1 10</li><li>2 11</li><li>3 12</li><li>4 15</li><li>5 16</li><li>6 17</li><li>7 18</li><li>8 19</li><li>9 20</li><li>10 22</li><li>11 24</li></ul><p>In the left side is index vector and in right side the content
The sorted vector that I hope to get is:</p><ul><li>1 2</li><li>2 2</li><li>3 3</li><li>4 4</li><li>5 5</li><li>6 6</li><li>7 7</li><li>8 8</li><li>9 9</li><li>10 10</li><li>11 11</li><li>12 12</li><li>13 13</li><li>14 14</li><li>15 15</li><li>16 16</li><li>17 17</li><li>18 18</li><li>19 19</li><li>20 20</li><li>21 21</li><li>22 22</li><li>23 23</li><li>24 24</li></ul><p>Thank for your help!</p>Camilo Corredorhttps://www.mathworks.com/matlabcentral/profile/authors/6782660-camilo-corredortag:www.mathworks.com,2005:Question/2371402015-08-28T00:59:33Z2015-08-28T07:22:12ZSolve overdetermined system of matrices<p>I have an overdetermined system of the form Ax = B, where A, x, and B are all matrices. My system looks like this:</p><pre class="language-matlab">A1 * x = B1
A2 * x = B2
...
AN * x = BN
</pre><p>I am trying to find the x which best fits my system. I initially attempted this using lsqonneg function, but this did not work because x, A, and B are matrices. I then manually wrote a least squares function:</p><pre> function [difference] = least_squares(x)
difference = zeros(m,n);</pre><pre> for i = 1 : number of equations
difference = difference + (A{i}*x - B{i}).^2;
end
end</pre><pre> eqn = @least_squares;
x = fmincon(eqn,x0);</pre><p>This solves the problem of matrix inputs. However, the fmincon and fminsearch functions still expect difference to be a scalar. Any suggestions for solving this problem are greatly appreciated!</p>Kellyhttps://www.mathworks.com/matlabcentral/profile/authors/6290149-kellytag:www.mathworks.com,2005:Question/2372592015-08-28T06:32:01Z2015-08-28T07:16:53Zunicode symbols on popupmenu / pushbutton<p>I am trying to create either array of buttons or a popupmenu with following unicode symbols (arrows) in text fields
←↑→↓↖↗↘↙
My initial attempt below</p><pre> selections = [char(8592), char(8593), char(8594), char(8595), char(8598), char(8599), char(8600), char(8601)]
h = uicontrol('Style', 'popupmenu');
set(h, 'Tag', 'popupHeading');
set(h, 'Units', 'pixels');
set(h, 'Position', [50 50 130 20]);
set(h, 'String', selections);</pre><pre class="language-matlab">h2 = uicontrol('Style', 'pushbutton');
set(h2, 'String', selections(2));
</pre><p>result is no text in uicontrol objects
and the cmd output of</p><pre class="language-matlab">Warning: popupmenu control requires a non-empty String
Control will not be rendered until all of its parameter values are valid
selections =
</pre><pre class="language-matlab">←↑→↓↖↗↘↙
</pre><p>I can get rid of the warning by cating blank string ('') into selections but symbols still wont appear.
Do you know any workaround to do this?</p><p>I am using matlab R2013a if it isnt possible in this version please provide info which version might support it</p>Thomashttps://www.mathworks.com/matlabcentral/profile/authors/3844385-thomastag:www.mathworks.com,2005:Question/2368262015-08-27T05:45:06Z2015-08-28T07:16:06ZHOW TO COUNT THE NUMBER OF GRIDS WHOSE HAVING THE OUTLINE CURVE OF THE IMAGE (TEMPLE) ?<p>HOW TO COUNT THE NUMBER OF GRIDS WHOSE HAVING THE OUTLINE CURVE OF THE IMAGE (TEMPLE) ?</p>SWAMINATHAN Ahttps://www.mathworks.com/matlabcentral/profile/authors/6611094-swaminathan-atag:www.mathworks.com,2005:Question/2372402015-08-28T05:56:31Z2015-08-28T07:00:55ZHow to iterate a differential equation in matlab?<p>I need to iterate a differential equation until the output (the value of p) converges. Here is the code I wrote;</p><pre> threshold = ((zeros(1,2048)));
old = p;
new = zeros(1,2048);</pre><pre> while norm( old-new) > threshold</pre><pre> old = p;</pre><pre> p = ((p * StateTransitionbwd) - (dd .* p));</pre><pre> new = p;</pre><pre class="language-matlab">end
</pre><p>In the equation I am using dp/dt as p. Do you know how should I treat this differential equation and what should I change in my code?</p><p>Thanks a lot.</p>Salman Saeedhttps://www.mathworks.com/matlabcentral/profile/authors/6568223-salman-saeedtag:www.mathworks.com,2005:Question/2372722015-08-28T07:00:44Z2015-08-28T07:39:52ZMatrix argument in Matlabs MLE function<p>Dear all,</p><p>I want to use Matlabs MLE function to find the maximum of a log-likelihood expression. The expression contains matrix multiplication of the unknown parameters (called theta here), so I want to submit a matrix. The matrix is of variable size, so I don't want to hard code any sizes.</p><p>What I've tried so far, with failed results, are seen below. First of all, I create some data that I use for all my trials:</p><pre class="language-matlab">global p b
p = [0.5 1 0.7; 0.4 0.5 0.2]'; %some matrix
b = [2 .6 .3 .1]; %some other matrix
theta0 = [1 1; 1 1; 1 1; 1 1]'; %initial guess of unknowns
y_meas = [2.32 3.17 2.53]; %measured values
</pre><p>Note that the matrix sizes above will not always be the same, they can vary.</p><p>Trial 1)</p><pre class="language-matlab">%Log-likelihood function
loglik = @(y_meas,theta) sum(sum(y_meas.*log( b*(p*theta)' ) - b*(p*theta)'));
</pre><pre> %Maximum likelihood estimation
est = mle(y_meas,'logpdf',loglik,'start',theta0)</pre><p>The above expression failes since I think you can only send and recieve individual arguments (not matrices or vectors) in MLE and the custom loglik function.</p><p>Trial 2)</p><pre class="language-matlab">%Create string argument with matrix indices like 'theta(1,1),theta(1,2),...'
[ro,co] = size(theta_true);
str = '';
for j = 1:co
for i = 1:ro
str = [str 'theta(' num2str(i) ',' num2str(j) '),'];
end
end
str = str(1:end-1); %Remove last comma
</pre><pre class="language-matlab">%Log-likelihood function
eval( ['loglik = @(y_meas,' str ') sum(sum(y_meas.*log( b*(p*theta)'' ) - b*(p*theta)''));'] );
</pre><pre> %Maximum likelihood estimation
est = mle(y_meas,'logpdf',loglik,'start',theta0(:));</pre><p>The above fails with unbalanced or unexpected parenthesis. I gather you cannot recieve arguments with indices in the custom function loglik?</p><p>Trial 3)</p><pre class="language-matlab">%Create string argument with matrix indices like 'theta11,theta12,...'
[ro,co] = size(theta_true);
str = '';
for j = 1:co
for i = 1:ro
str = [str 'theta' num2str(i) num2str(j) ','];;
end
end
str = str(1:end-1); %Remove last comma
</pre><p>Like the arguments above, I get no errors when passing them to the custom function, but I get the problem of how to perform the matrix multiplication.</p><p>Does anyone have an idea of how to use a variable number of arguments in MLE for a custom log-likelihood function containing matrix multiplication with the unknowns?</p><p>Thank you!</p>Idahttps://www.mathworks.com/matlabcentral/profile/authors/2637962-idatag:www.mathworks.com,2005:Question/2372412015-08-28T06:01:40Z2015-08-28T06:35:31ZHow to set mesh plot to be in the limit -3 to 3<pre class="language-matlab">x = xy(:,1); y = xy(:,2);
v = 0.2.*cos(x)+y.*exp(-x.^2-y.^2);
[xq,yq] = meshgrid(-3:.2:3, -3:.2:3);
vq = griddata(x,y,v,xq,yq);
figure;
k=mesh(xq,yq,vq);
h = gca;
set(h,'XLim',[-3 3]);
set(h,'YLim',[-3 3]);
set(h,'ZLim',[-4 4]);
xlabel('x');
ylabel('y');
zlabel('N');
direction = [1 0 0];
rotate(k,direction,25)
colormap hsv;
colorbar;
</pre>Subha manoprakashhttps://www.mathworks.com/matlabcentral/profile/authors/6831347-subha-manoprakashtag:www.mathworks.com,2005:Question/2372492015-08-28T06:23:29Z2015-08-28T06:23:29Zproblem with automatic stoping of controller<p>i implemented inverter control algorithm using simulink on F28335 using target specific blocks. auto generated code working fine on board, as i can see expected result on physical scope. After 6 minutes controller automatically stops performing control action. I haven't configured any such things. what can be the reason behind this?
i posted same query on TI forum also.
https://e2e.ti.com/support/microcontrollers/c2000/f/171/p/447924/1612963#1612963</p>ashish ahirhttps://www.mathworks.com/matlabcentral/profile/authors/6064237-ashish-ahirtag:www.mathworks.com,2005:Question/2304552015-07-20T09:01:44Z2015-08-28T06:13:16ZTrue heading and Wind direction<p>Hello,</p><p>Given I have wind value, wind direction and true direction</p><p>May i know if in matlab, we have a function which resolves the wind into components parallel and perpendicular to my true direction?</p><p>In the end, I want to know if we have headwind or tailwind component?</p><p>Thanks</p>yashvinhttps://www.mathworks.com/matlabcentral/profile/authors/4047317-yashvintag:www.mathworks.com,2005:Question/2346842015-08-19T16:34:28Z2015-08-28T06:05:14Zproblem with IFFT and Convolution<p>I’m having difficulty with executing IFFT and convolution</p><p>I want to see the output of a system with an input sine wave x(t) and transfer function H(f). In order to get the output y(t), I used IFFT with the transfer function to convert it from the frequency domain to the time domain. After which I convoluted both h(t) and x(t) to obtain y(t).</p><p>However when I plot y(t) I get a distorted signal. Could someone please instruct me as to what I did wrong? Your help would be highly appreciated</p><pre class="language-matlab">%Transfer function (multipathmodel)
f = 0:1*10^6:30*10^6; %frequency of multipathmodel
a = 0+(7.8*10^-10)*f.^1;
l = [200 225]; %length of wire
g = [0.55 0.45];
Vp = 150*10^6;
h = 0;
for i = 1:2
temp = (g(i)*exp(-a.*l(i))).*exp((-f.*j*2*pi)*l(i)/Vp);
h = h + temp;
end
</pre><pre class="language-matlab">%h is in the frequency domain
</pre><pre class="language-matlab">%Multipathmodel
d1 = 10*log(abs(h)); %H(f)/dB
d2 = ifft(h); %Impulse response
</pre><pre class="language-matlab">%sine wave
fo = 3*10^6; %frequency of the sinewave
Fs = 2^nextpow2((fo*10*2)+fo); %samplingrate
Ts = 1/Fs; %sampling time interval
E = 1/fo; %duration of sinewave (t)
t = 0:Ts:E; %xaxis
x = sin(2*pi*fo*t); %sinewave equation
</pre><pre class="language-matlab">%convolution of sine wave and transfer function
y = conv2(x,d2);
</pre><pre class="language-matlab">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
</pre><pre class="language-matlab">%plot transfer function
figure(1)
subplot(2,1,1)
plot(f,d1)
title('Transfer function of Twopathmodel')
xlabel('frequency')
ylabel('H(f)/dB')
grid on
%plot the sine wave
subplot(2,1,2)
plot(t,x)
title('Sine wave')
xlabel('Time secs')
ylabel('Amplitude')
grid on
</pre><pre class="language-matlab">%plot the impulse response of the transfer function
figure(2)
t2 = (0:E/(length(d2)-1):E);
plot(t2,d2)
%axis([0 3.5*10^-6 -1 1])
title('Impulse response')
</pre><pre class="language-matlab">%plot the convolution
t1 = (0:E/(length(y)-1):E);
figure(3)
plot(t1,y)
%axis([0 3.5*10^-6 -1 1])
title('Convolution')
</pre>Maxilyn Tanhttps://www.mathworks.com/matlabcentral/profile/authors/6764057-maxilyn-tan