https://in.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-05-28T18:30:02Ztag:in.mathworks.com,2005:Question/3422752017-05-28T17:21:39Z2017-05-28T18:30:02ZProblem showing word in gui<p>Hi everyone, i am trying to show a word that is made from a cicle of characters on a static text using Guide.</p><p>The problem is that when the cicle ends the static text box shows nothing, the code for the static text box is the following:</p><pre class="language-matlab">set(handles_part2.char3,'String',palabra);
</pre><p>I am using this code :</p><pre class="language-matlab">for l = 1:length(palabra)
pause(1);
set(handles_part2.char1, 'String', palabra(l));
end
</pre><p>To show every character of the word and i have no problem, but when i try to show the word it shows nothing, hope anyone can help me.</p>Luis Duranhttps://in.mathworks.com/matlabcentral/profile/authors/10394333-luis-durantag:in.mathworks.com,2005:Question/3422712017-05-28T15:33:51Z2017-05-28T18:29:59ZMatlab code from literature gives errors<p>have this code from a book I recently looked at, I want to implement the code but I get loads of errors , can someone help me localize the errors or possibly make a runnable example?</p><pre class="language-matlab">function [P,b]=AmericanPrice(r,delta,sigma,K,nx,nt, Xhat,That)
%Usage:P=AmericanPrice(r,delta,sigma,K,nx,nt,Xhat,That)
%Example:P=AmericanPrice(0.08,0.12,.2,100,50,10,300,3)
dx=Xhat/nx;
dt=That/nt;
for i=1:nx-1
A(i,i:i+2)=[((r-delta)*dt*i-sigmaˆ2*dt*iˆ2)/2...
1+r*dt+sigmaˆ2*dt*iˆ2
(-(r-delta)*dt*i-sigmaˆ2*dt*iˆ2)/2];
end
P(:,1)=max(K-[0:dx:Xhat],0);
</pre><pre class="language-matlab">if(delta==0)
b(1)=K;
else
b(1)=min(K,K*r/delta);
end
</pre><pre class="language-matlab">for j=2:nt+1
bn=0; run=1;
while(run)
An=[A(1+bn:end,1+bn:end)];
An(end+1,end-1:end)=[-1 1];
An(end+1,1)=1;
Cn=[P(bn+2:nx,j-1)’ 0 K-bn*dx]’;
Pn=inv(An)*Cn;
if(Pn(2)$<$K-((bn+1)*dx))
bn=find(sign(diff(Pn)/dx+1)-1,1,{’last’})+bn;
else
b(j)=bn*dx; run=0;
end
end
P(:,j)=[K-[0:bn-1]*dx Pn’];
end
</pre><p>what i have done so far: i changed the sigmaˆ2 to sigma*sigma, same thing with i. Then i replaced the ’ with '. I did not know what to d o with "..." The error i get is</p><pre class="language-matlab">Undefined function 'find' for input arguments of type 'cell'.
</pre><pre class="language-matlab">Error in FDM (line 28)
bn=find(sign(diff(Pn)/dx+1)-1,1,{'last'})+bn;
</pre>Khttps://in.mathworks.com/matlabcentral/profile/authors/3790244-ktag:in.mathworks.com,2005:Question/3422762017-05-28T17:34:05Z2017-05-28T18:18:17ZIs this MATLAB example wrong? - Dividing the FFT by the signal length<p>Someone in <a href = "https://math.stackexchange.com/questions/636847/understanding-fourier-transform-example-in-matlab">this link</a> claim that</p><pre class="language-matlab">the MATLAB example is actually wrong in dividing the fft
by the signal length in the time domain (which is L)
</pre><pre class="language-matlab">The right scaling needed to adhere to Parseval's theorem would be
dividing the Fourier transform by the sampling frequency.
</pre><p>Is it correct? Should I divide the result from FFT by <b>sampling frequency</b> instead of <b>signal length</b>?</p><p>Here is the Matlab example of fft function: <a href = "https://www.mathworks.com/help/matlab/ref/fft.html">https://www.mathworks.com/help/matlab/ref/fft.html</a></p>azzendixhttps://in.mathworks.com/matlabcentral/profile/authors/7436388-azzendixtag:in.mathworks.com,2005:Question/3422692017-05-28T15:23:58Z2017-05-28T18:14:28ZI created the app in matlab, but when I try to plot using quiver it opens a new window. Its not using UIAxes.<p>plot(app.UIAxes,quiver(xo,yo,x1n,y1n,0));</p>Aleksandar Paunovichttps://in.mathworks.com/matlabcentral/profile/authors/10384795-aleksandar-paunovictag:in.mathworks.com,2005:Question/3422272017-05-28T04:09:25Z2017-05-28T18:14:03Zuse matlab to write a software that translates input symbolic expression to hdl ？<p>Hi:
I am working on a project to design a software generator to produce hardware IP. The software acts like a compiler that translates the symbolic expression (such as a*b+c) into the corresponding arithmetic unit (in HDL). My supervisor suggests me designing the software in Matlab since it includes the toolbox for symbolic expression. I think I needs a lexer to separate and analysis a stream of characters and also a parser to takes those tokens produced from lexer. I am new to the compiler design using Matlab. Can anybody recommend some tutorials related to this topics?</p><p>Thank you
Jiaji Chen</p>Jiaji Chenhttps://in.mathworks.com/matlabcentral/profile/authors/9674694-jiaji-chentag:in.mathworks.com,2005:Question/3422162017-05-27T23:01:18Z2017-05-28T17:58:38ZHow can I modify the findpeaks command to give me a width at 80% of peak height (instead of at the build in 'halfheight')? <p>I am trying to analyze peaks but and need to determine the width of signal at 80% of the peak height. Matlab has a built in criterion when you specify findpeaks(...,'WidthReference",'halfheight') and this gives you 50%.</p><p>I have tried to modify the code but have so far been unsuccessful. If anybody can help I would really appreciate it.</p><p>Thank you</p>David Zimmermanhttps://in.mathworks.com/matlabcentral/profile/authors/4214395-david-zimmermantag:in.mathworks.com,2005:Question/3422782017-05-28T17:56:08Z2017-05-28T17:56:36Z Neural networks for Classification using NNTOOL<p>Hi everyone ,
I create a neural networks for Classification using NNTOOL. I want to know how can i call it if i want to use it to classify another test set ?</p>afefhttps://in.mathworks.com/matlabcentral/profile/authors/9902982-afeftag:in.mathworks.com,2005:Question/3416172017-05-23T20:51:30Z2017-05-28T17:34:57ZFunction gives ans=0 when comparing text<p>Bad title i know, but here is the problem:
I have made a function that should take a social security number as an input and then return the persons name and income and taxes paid.
When i use and input it returns the answer 0.
The files are imported from excel and made into cell, so i guess the problem lies within the strcmp. what can i use when i compare numbers?</p><pre class="language-matlab">global Citizens Income Taxes
Citizens=[];
Income=[];
Taxes=[]
%Importing:
[~,~,Citizens]=xlsread('Citizens.xlsx');
[~,~,Income]=xlsread('Income.xlsx');
[~,~,Taxes]=xlsread('Taxes.xlsx');
Function file:
</pre><pre class="language-matlab">function [Name,personalIncome,taxespaid]=socialsecuritylook(serialnumber)
global Citizens;
global Income;
global Taxes;
Name=0;
personaliIncome=0;
taxespaid=0;
serialnumber=0;
</pre><pre> for i=2:size(Citizens,1)
if strcmp(Citizens{i,1},serialnumber);
Name = Citizens{i,2};
end
end
for i=2:size(Income,1);
if strcmp(Income{i,1},serialnumber)
personalIncome = {i,2}
end
end
end</pre><p>original excel files:</p><pre class="language-matlab">Citizens file:
Security number Name Gender Region
103920482 Hans Kale M 10
492012903 Sara Green F 2
</pre><pre> Income file:
Security number Income
103920482 72000
492012903 54350</pre><pre class="language-matlab">Taxes file:
Region basic tax tax limit higher rate tax
10 25 50000 45
2 20 40000 50
</pre><p>thanks in advance</p>ChrisKhttps://in.mathworks.com/matlabcentral/profile/authors/10194517-chrisktag:in.mathworks.com,2005:Question/3422702017-05-28T15:32:51Z2017-05-28T17:20:00ZOpen *.nds files - Nikon proprietary Microscopy Video File<p>Hy everybody,</p><p>Would anyone know how to open, or at least read a Nikon proprietary NDS file (Not ND2).</p><p>- fopen does not work,</p><p>- imfinfo doesn't ether.</p><p>Thank you...</p>Roberthttps://in.mathworks.com/matlabcentral/profile/authors/5066475-roberttag:in.mathworks.com,2005:Question/3422582017-05-28T14:00:03Z2017-05-28T17:05:50ZNumber of pixels inside a pixel circle help!!!<pre class="language-matlab">my_image =imread('C:\Users\mojtaba.houballah\Desktop\Matlab\road map.PNG');
</pre><pre class="language-matlab">for R=1:617
</pre><pre> for C=1:306</pre><pre> pixel=my_image(R,C);</pre><pre> if pixel<=200 , pixel=0;</pre><pre> [xc,yc]=circle(R,C,0.000000000001);</pre><pre> [xroad,yroad] = find(Roads(:)==0 | Roads(:)==255); end</pre><pre> if (235 < pixel) && (pixel<=250) , pixel= 237; end</pre><pre> if pixel>254 , pixel=255; end</pre><pre> Roads(R,C)=pixel;</pre><pre> end
end
[o,p]=inpolygon(xroad,yroad,xc,yc);</pre><p>Hello,
i have the above code, my goal is to cimpute the number of pixels inside the circle that i draw (i dont know if i defined the circles correctly), the problem that this code is giving me the whole pixel count of the picture, can someone help, thank you in advance</p><p>ps: im very new to matlab</p><p>find attached the picture i am using</p>mojtaba Houballahhttps://in.mathworks.com/matlabcentral/profile/authors/6897822-mojtaba-houballahtag:in.mathworks.com,2005:Question/3422742017-05-28T16:48:20Z2017-05-28T16:58:49ZMatlab does not plot my function, why?<p>Hi want this function to plot but i'm getting no error or a curve...</p><p>rLP = 0:1:200;</p><p>PrL = rLP * 9 /(rLP+12);</p><p>plot(rLP, PrL); grid;</p>Zeg du Toithttps://in.mathworks.com/matlabcentral/profile/authors/10098446-zeg-du-toittag:in.mathworks.com,2005:Question/3421972017-05-27T19:33:04Z2017-05-28T16:57:06ZWhy matlab returns inaccurate response for rank of my matrix?<p>This is my matrix:</p><pre> A=
6.07787530038946e+15 0 0 0 0 0 0 0
0 6.07787530038946e+15 0 0 0 0 0 0
0 0 6.07787530038946e+15 0 0 0 0 0
0 0 0 1215578336877.89 0 0 0 0
0 0 0 0 1215578336877.89 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 -1.47264000000000e-12 0
0 0 0 0 0 0 0 -1.96352000000000e-16</pre><p>When ask matlab to say the rank of A it returns 5, while it is 7 as you see. why it returns 5, and how to fix it?</p>Mehdihttps://in.mathworks.com/matlabcentral/profile/authors/3362961-mehditag:in.mathworks.com,2005:Question/3422192017-05-27T23:42:17Z2017-05-28T16:51:06ZHello, I have two question<p>Hello, I have two question-</p><ol><li>I need to plot the below figure in a new form which should show only the region which is blue in color into red color and in a transparent cube. The figure should not show any other mesh except the blue region (in red with mesh).</li><li>Second thing is at present the dimension displaying on each axis is according to the size of meshgrid(49*33*33), I need to change it to actual room size (12*4*5).</li></ol><p>Thanks for your help</p><img src = "/matlabcentral/answers/uploaded_files/78939/wmz_real_111_0.5.bmp">Nikita Johnsonhttps://in.mathworks.com/matlabcentral/profile/authors/9672537-nikita-johnsontag:in.mathworks.com,2005:Question/3422722017-05-28T16:01:55Z2017-05-28T16:44:56ZDefining integers in Matlab<p>Good evening,</p><p>I am in need to define a variable in Matlab as an integer, according to my text book, I have to insert a command that calls a function from Maple in Matlab, but when introducing the commands, I get the following error</p><pre class="language-matlab">Undefined function or variable 'maple'.
</pre><p>I have included a picture of my textbook that explains the procedure.</p><p>Am I missing any files or expansion pack? if so, where can I find it?</p><img src = "/matlabcentral/answers/uploaded_files/78977/IMG_20170528_180511.jpg"><p>Thanks!</p>Álvaro Soler Verdúhttps://in.mathworks.com/matlabcentral/profile/authors/8687456-alvaro-soler-verdutag:in.mathworks.com,2005:Question/3257742017-02-19T04:28:15Z2017-05-28T16:43:26ZGenerating piecewise in r2016a<p>Hello!</p><p>Using r2016a with symbolic math toolbox, but perhaps it is lacking 'piecewise'? Hoping to work with the following function, but have failed with various approaches. Thank you in advance for your suggestions.</p><p>Function:</p><pre> (3*x^2)/100 + 30 if x<22.3607
x^2/100 + 40 if 22.3607<=x<=109.5445
(3*x^2)/400 + 70 if x>109.5445 </pre><p>Option 1) SMT would probably allow:</p><pre> syms y x
y(x) = piecewise([x<22.3607, (3*x^2)/100 + 30], [22.3607<=x<=109.5445, x^2/100 + 40], [x>109.5445, (3*x^2)/400 + 70)]);</pre><pre> Result:
>> Undefined function or variable 'piecewise'.</pre><p>Option 2) Create function in .m file:</p><pre> function y = y(x)
if x<=22.3607;
y = (3*x^2)/100 + 30;
else if 22.3607<x<=109.5445;
y = x^2/100 + 40;
else if 109.5445<x;
y = (3*x^2)/400 + 70;
end
end
end</pre><pre> Result:
>> y_piecewise
Not enough input arguments.</pre><pre> Error in y_piecewise (line 3)
if x<=22.3607;</pre><p>Option 3) Use heavyside:</p><pre> y = ['(heaviside(x)-heaviside(x-22.3607))*((3*x^2)/100 + 30) + ' ...
'(heaviside(x-22.3607)-heaviside(x-109.5445))*(x^2/100 + 40) + ' ...
'(heaviside(x-109.5445)-heaviside(x-800))*((3*x^2)/400 + 70)'];</pre><pre> yinv = finverse(y,x)</pre><pre> Result (trying to compute inverse):
>>yinv = 10.0*(x - 40.0)^(1/2)</pre><p>I would like to be able to input a value for x into this piecewise equation and receive a value for y. I would ideally like to do this for the inverse of the above piecewise function as well. In addition, I would like to compute the diff() and int(), so I believe a symbolic function would be best suited for this. Thoughts? Thank you!!</p><p>- Bryan</p>Bryan Parthumhttps://in.mathworks.com/matlabcentral/profile/authors/9641794-bryan-parthumtag:in.mathworks.com,2005:Question/2871362016-06-02T22:38:30Z2017-05-28T16:27:48ZBuilding a Matlab APP with multiple GUIs<p>Hi everyone.</p><p>I am trying to build a Matlab APP for a code that features multiple (sequential) interfaces. It builds it without complaints and runs the first GUI window well. However, when I'm trying to launch the next GUI window (using a 'Next' button in the first GUI), it complains that it can't find its associated 'm' file,</p><p><i>Undefined function or variable 'GUI2'.</i></p><p>Of course, the GUI2.m function WAS included in the package, and through its own analysis (that is, GUI2.m was not included <i>a posteriori</i> as a shared resource).</p><p><b>Questions:</b></p><p>Does anyone else experienced this sort of issue?</p><p>Does APP packing work at all with multiple GUIs?</p><p>And, while we're at it, can I create a package for a code that spreads through various folders/sub-folders? Moving from one folder to the next also seems to cause the execution to fail.</p><p>I appreciate any help!</p><p>Ionut</p>Ionut Dragos Moldovanhttps://in.mathworks.com/matlabcentral/profile/authors/8184555-ionut-dragos-moldovantag:in.mathworks.com,2005:Question/3422472017-05-28T10:46:21Z2017-05-28T16:23:39ZR2017a parfor error when starting parpool inside function body<p>Hello,</p><p>I'm testing the work of the distributed cluster MATLAB R2017a (in practice I use R2015b). MDCE components runs on Linux machines (Ubintu and Mint), client is Linux machine too.
I have some problems in the new version, which did not arise in the previous one:</p><p>If I run the cluster (named MJSP17 in example) inside the body of a simple function " <i>main.m</i>" that uses a table (with three columns) as input arguments, I get an error in accessing variables:</p><pre class="language-matlab">Warning: While loading an object of class 'table':
Invalid default value for property 'propertyNames' in class 'table':
Error: File: metaDim.m Line: 246 Column: 20
Arguments to IMPORT must either end with ".*" or else specify a fully qualified class name: "matlab.internal.tabular.private.tabularDimension.checkReservedNames_impl" fails this test.
> In parallel.internal.pool.deserialize (line 9)
In parallel.internal.pool.deserializeFunction (line 12)
In remoteParallelFunction (line 33)
Error using main (line 28)
Struct contents reference from a non-struct array object.
</pre><p>1. Script that calls <i>main.m</i>:</p><pre class="language-matlab">% Generate filelist
gcpfilelist = {[cd filesep 'main.m']};
</pre><pre class="language-matlab">% Make an example of "data" table: | ID | PeriodID | Value |
numid = 1000; % Number of unique ID
maxlength = 74; % Maximum number of Period for every ID
varlength = randi(maxlength, numid, 1) + 1;
data = table(repelem((1:numid), varlength)', ...
cell2mat(arrayfun(@(x) (1:x)', varlength, 'UniformOutput', false)),...
randi(10^6, sum(varlength), 1), 'VariableName', {'FcID' 'PeriodID' 'Value'});
</pre><pre class="language-matlab">% Call main finction
main( data, gcpfilelist );
</pre><p>2. <i>main.m</i> example:</p><pre class="language-matlab">function [ batchoutput ] = main( data, varargin )
%MAIN example of error using tables in parfor (MATLAB R2017a)
% INPUT:
% data - table with variables | ID | PeriodID | Value |
% varargin - project's list of m-file (for addAttachedFiles(gcp, gcpfilelist))
% OUTPUT:
% batchoutput - output dummy (unique ID data);
%
%
</pre><pre class="language-matlab">if ~isempty(varargin)
gcpfilelist = varargin{1};
end
</pre><pre class="language-matlab">unqid = unique(data{:,'FcID'});
n = numel(unqid);
batchoutput = cell(n, 1); % Output
</pre><pre class="language-matlab">%% Make main processing (using functions from project folders)
</pre><pre class="language-matlab">parpool('MJSP17', 'SpmdEnabled', false);
</pre><pre class="language-matlab">% addAttachedFiles(gcp, gcpfilelist);
% fprintf(1, '============== ATTACHED GCP FILES =================\n');
% curgcp = gcp; curgcp.AttachedFiles
% fprintf(1, '===================================================\n');
</pre><pre class="language-matlab">parfor j = 1:n %numel(metascenariofc.FcID)
</pre><pre> curid = unqid(j); % Get current FcID
curFcIDdata = data(data.FcID == curid, :);
batchoutput{j} = curFcIDdata;</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">delete(gcp('nocreate'));
</pre><pre class="language-matlab">% Completeness check
any(cellfun(@(x) isempty(x), batchoutput))
</pre><pre class="language-matlab">end
</pre><p>The problem is solved by the transfer list of project's working files ( <i>gcpfilelist</i>) to the gcp.</p><p>3. Uncomment in <i>main.m</i>:</p><pre class="language-matlab">addAttachedFiles(gcp, gcpfilelist);
fprintf(1, '============== ATTACHED GCP FILES =================\n');
curgcp = gcp; curgcp.AttachedFiles
fprintf(1, '===================================================\n');
</pre><p>But, this is extremely inconvenient, and besides, this error did not arise in R2015b.</p><p>Tell me, please, how to avoid the occurrence of this error without sending the structure of project files to all nodes of the cluster?</p><p>Thank you!</p>Jonashttps://in.mathworks.com/matlabcentral/profile/authors/2133120-jonastag:in.mathworks.com,2005:Question/3422732017-05-28T16:22:41Z2017-05-28T16:26:55ZHelp adjust the code for Fourier Transform of square pulse :(<pre class="language-matlab">clear;
</pre><pre class="language-matlab">fs = 20e3; %sampling freqency
tfin = 10e-9; %beggining and end of time for samples of square pulse
N = 1025;% number of steps in linspace, odd to make centered at zero
width = 1e-9; % actual width of square pulse, 1 nanosecond
t = linspace(-tfin,tfin,N);
% The correct way to make f.
dt = t(2)-t(1);
T = t(end)-t(1) + (t(2)-t(1));
f = 1/T * (-(N-1)/2 : (N-1)/2);
</pre><pre class="language-matlab">y = rectpuls(t,width);%makes the actual square pulse
plot(t,y)
Y = width*fft(y); %fourier transform of square pulse: ATsinc(fT)
%where f is a frequency variable. A is the amplitude of the pulse,
%assumed to be 1.
Yplot = fftshift(Y);
%fftshift changes the axis so zero is at the center
%and have negative and positive frequencies on both sides of the axis.
figure;
plot(f,abs(Yplot))
hold on;
%this plots a red circle on where the first zero occurs on a graph of the
%sinc function. It should be exactly the width of the square pulse
% which is 1 nanosecond.
plot(1/width,width*sinc((1/width)*width),'ro');
</pre><img src = "/matlabcentral/answers/uploaded_files/78983/20170529_011310.jpg"><img src = "/matlabcentral/answers/uploaded_files/78985/20170529_011255.jpg"><p>Sorry I'm still beginner to Matlab, I have a code up there but I need to adjust the code so the result will be the same as in the picture. Can anyone help me to adjust the code to be similar to the picture. Really need help pliss :(</p>Bot Natehttps://in.mathworks.com/matlabcentral/profile/authors/10394562-bot-natetag:in.mathworks.com,2005:Question/3422502017-05-28T11:19:36Z2017-05-28T16:20:15Zhow to use Feature Selection Library of Giorgio (MATLAB Toolbox)<p>how, to use Feature Selection Library (MATLAB Toolbox) please</p>mezaache hatemhttps://in.mathworks.com/matlabcentral/profile/authors/4186468-mezaache-hatemtag:in.mathworks.com,2005:Question/3410082017-05-19T14:41:46Z2017-05-28T16:16:53Z Write a function called approximate_e that uses the following formula to compute e, Euler’s number: = 1 ! ∞ = 1+1+ 1 2 + 1 6 + 1 24 +⋯ Instead of going to infinity, the function stops at the smallest k for which the approximation differs from<pre class="language-matlab">function [est, n ] = approximate_e( delta )
%APPROXIMATE_E Summary of this function goes here
% Detailed explanation goes here
n =1;
est = 0;
while abs(exp(1)> delta
if n ==1
est = 1;
end
if n == 2
est = 2;
end
if n >2
est = est+1/prod(1:(n-1));
end
n = n + 1;
if n >10000
</pre><pre> break;
end
end</pre><p>could you please tell me how one can solve above mention question.
thanks</p>Wasi von Deutschlandhttps://in.mathworks.com/matlabcentral/profile/authors/10267023-wasi-von-deutschlandtag:in.mathworks.com,2005:Question/3422372017-05-28T07:12:24Z2017-05-28T16:11:57ZI am getting following error. "??? Error using ==> plot Conversion to double from sym is not possible."<pre class="language-matlab">clc
clear
syms x y
y = Dsolve('Dy = (x^3 - 5*y + 3*x)/x','x')
pretty(y)
% num2str(x)
xx = 1:.01:3;
yy = subs(y,x,xx)
</pre><pre class="language-matlab">plot(xx,yy)
</pre>Taha Abbas Bin Rashidhttps://in.mathworks.com/matlabcentral/profile/authors/7949631-taha-abbas-bin-rashidtag:in.mathworks.com,2005:Question/3422602017-05-28T14:10:46Z2017-05-28T16:07:18ZError installing third party package Arduino software<p>hi!
I tried to install Simulink Support Package for Arduino Hardware
but i failed and i received this error
Error installing third party package Arduino software: Invalid zip file "C:\MATLAB\SupportPackages\R2013a\downloads\arduino-1.0-windows.zip"
PS : i have MATLAB R2013a</p>youness Riadihttps://in.mathworks.com/matlabcentral/profile/authors/9447470-youness-riaditag:in.mathworks.com,2005:Question/3422682017-05-28T15:19:35Z2017-05-28T15:58:26ZHow can i create a square matrix from values that user inputs in a script?<p>The code for inputting values from the user is:</p><pre class="language-matlab">for i=1:n
fprintf ('enter value %d: ',i);
a(i)=input ('');
end
%Now how can I arrange those values into a square matrix?
</pre>Arafa-Diliphttps://in.mathworks.com/matlabcentral/profile/authors/10396264-arafa-diliptag:in.mathworks.com,2005:Question/3422102017-05-27T21:17:25Z2017-05-28T15:52:02ZWorking with phone number data. Number to String<p>Using a bunch of data from an excell sheet im reading in phone numbers to sort the problem is that some of the numbers matlab reads in as numbers not strings if they dont have hypens for example >>> 9301923334 is a number but 930-192-3334 is a string when import them I use xlsread like this.</p><pre class="language-matlab">[numbers,strings,raw] = xlsread('contacts.xls');
for i = 1:length(numbers)
newarray(i) = num2cell(numbers(i));
end
</pre><p>this gives me an array of numeric data and string data which is great but the numbers array always uses scientific notation in when i use num2cell so the phone number will show up like >> 9.301923334+09 i need some way to get this to be formatted like a phone number or at least in a cell with just the numbers
Thanks for all your help!!!</p>Camhttps://in.mathworks.com/matlabcentral/profile/authors/8730993-camtag:in.mathworks.com,2005:Question/3416242017-05-23T22:02:54Z2017-05-28T15:48:32ZShape a transferfunction to measurement data in Control System Designer<p>Hello everyone,
For a self study assignment I have to create the transfer function of measurementdata to later shape a controller around. The data of the measurement is already analysed and I'm able to make bode plots out of it. The problem is that I can't find a way of fitting a magnitude plot with a known transfer function to the one of the measurements. I first tried using the MATLAB function 'tfest' but this didn't give coherent results (looks more like: as long as a lot of points are on the line, it must be correct).</p><p>I then tried to use the 'Control System Designer' app in MATLAB. This works great but comparing the output to the measurement plot is something I have to do by hand as of now. Does anyone know if it is possible to get the magnitude plot from the measurements into this app or is there a way to quickly get a visual feedback on whether or not both plots align?</p><p>Thanks in advance!</p>Jorishttps://in.mathworks.com/matlabcentral/profile/authors/7856034-joristag:in.mathworks.com,2005:Question/3365502017-04-21T15:53:21Z2017-05-28T15:48:25ZArduino Due : Impossible to use the fonctiobn pulsein()<p>Hello,</p><p>I want to run an ultrasonic sensor HC-SR04 with an Arduino Due with simulink</p><p>I program my s-function</p><p>Outputs:</p><pre class="language-matlab">digitalWrite(6, HIGH);
delayMicroseconds(10);
digitalWrite(6, LOW);
Distance[0] = pulseIn(7, HIGH)/58;
</pre><p>I pass all the details off the code. I have tried lot of thing on the code and with another sensor (grove ultrasonic sensor). I had a look with an oscilloscope too..</p><p>I know my code is good but my problem is that pulsein() never send me a good value.</p><p>I run succefully a code working with interuption but I want to know why the function pulsein() is not working</p><p>I run Matlab R2017A</p><p>Is someone add the same problems too? and is someone have a solution?</p><p>Thank you</p>Girard Thomashttps://in.mathworks.com/matlabcentral/profile/authors/1912052-girard-thomastag:in.mathworks.com,2005:Question/3421092017-05-26T18:26:25Z2017-05-28T15:40:26Zplotxx scattered plot with smooth line and marker<p>I am using plotxx, i want to replicate the scattered chart with smooth lines and markers from excel in matlab.
Any help?</p>Kathyhttps://in.mathworks.com/matlabcentral/profile/authors/10376926-kathytag:in.mathworks.com,2005:Question/3422482017-05-28T10:58:59Z2017-05-28T15:39:43Zhow do i keep my format when exporting to csv or excel<p>I have a file:</p><pre> serialnumber income
'12491954158' [21050]
'23521956458' [35235]
'04311902557' [59305]</pre><p>i want to export both columns to either csv or excel including a third column containing the four middle numbers of the first column.
i have tried the following:</p><pre class="language-matlab">fileID = fopen('export.csv','w');
for i=2:length(data)
serialnumber=data{i,1};
income=data{i,2};
birth=ssn(5:8);
C=cell(1,3);
C{1,1}=serialnumber;
C{1,2}=income;
C{1,3}=birth;
fprintf(fileID,'%s; %d; %s; \n',C{1:3});
</pre><p>this gives me a desired output in excel</p><pre> 12491954158 21050 1954
23521956458 35235 1956
4311902557 59305 1902</pre><p>The problem is, that the serialnumbers which start with a zero looses the first number (e.g. last serialnumber above).
can i do something about the format, so the number will be intact?
and is it possible to export the columns as string, num, and string so i can import it again in the same format?</p>ChrisKhttps://in.mathworks.com/matlabcentral/profile/authors/10194517-chrisktag:in.mathworks.com,2005:Question/3422642017-05-28T14:42:49Z2017-05-28T15:35:15Zpvalues equals to zero?<p>The pvalues of the coefficients and model are equal to zero. Are they too significant to be true?</p><pre class="language-matlab">mdl =
</pre><pre class="language-matlab">Nonlinear regression model:
Emod ~ [Nonlinear formula with 7 coefficients and 9 predictors]
</pre><pre class="language-matlab">Estimated Coefficients:
Estimate SE tStat pValue
________ __________ ______ ___________
</pre><pre> b1 4.5028 0.05506 81.78 0
b2 0.99989 0.00011413 8761.1 0
b3 4.3701 0.048136 90.786 0
b4 0.99986 3.0081e-05 33239 0
b5 1.0002 0.00125 800.15 0
b6 1.0246 0.004444 230.55 0
b7 4.4177 0.065778 67.16 8.3514e-279</pre><pre class="language-matlab">Number of observations: 597, Error degrees of freedom: 591
Root Mean Squared Error: 3.7
R-Squared: 0.348, Adjusted R-Squared 0.342
F-statistic vs. zero model: 7.69e+03, p-value = 0
</pre>wesleynotwisehttps://in.mathworks.com/matlabcentral/profile/authors/10338091-wesleynotwisetag:in.mathworks.com,2005:Question/3422672017-05-28T15:19:01Z2017-05-28T15:19:01ZCreate a function - with cross reference<p>Hello,</p><p>I hope you are able to help me. Im fairly new to Matlab and need some help.</p><p>My question is that I have 3 excel sheets that I have imported through xlsread. In 1 document, I have Income (social security number that correlates with income), document 2, I have citizens (Social security number that correlates to name, gender and which region they live in), and the final document I have Taxes (region that correlates to amount of tax you pay)</p><p>My issue is that now I have to calculate the paid tax in each region and I dont know how to do so.</p><p>I have no idea of what to do, besides that I need to get the region, correlate it to the social security number to finally get the income. Can someone please help me?</p><p>Thank you in advance,
- Emil</p>Matrix-Matlabhttps://in.mathworks.com/matlabcentral/profile/authors/7603327-matrix-matlabtag:in.mathworks.com,2005:Question/3418992017-05-25T12:05:31Z2017-05-28T15:07:21ZData returned by Audioread<p>I have a question regarding the audioread function in Matlab. Audioread('file.wav') will return a normalized data of -1 to 1 that represents the amplitude of the sound.
My question is, Are sensors (ex. Mica2) when acquire a sound signal and after doing the AD sampling will give me the same samples data that i'll get using Audioread?</p>Afnan H.https://in.mathworks.com/matlabcentral/profile/authors/8036168-afnan-htag:in.mathworks.com,2005:Question/3422652017-05-28T14:49:05Z2017-05-28T15:17:17ZRandom Value Impulse noise added to every pixel ? How to generate labels?<pre class="language-matlab">I = im2double(imread('barbara.png'));
imshow(I);
</pre><pre class="language-matlab">s = size(I);
S = s(1) * s(2);
OriginalImageVector= reshape(I, S ,1);
</pre><pre class="language-matlab">p = 0.5; % p between 0 and 1
noisyimage = (I + p*rand(size(I)))/(1+p);
imshow(noisyimage, []);
</pre><pre class="language-matlab">s2 = size(noisyimage);
S1 = s2(1) * s2(2);
NoisyImageVector= reshape(noisyimage, S1 ,1);
</pre><p>When I compare the values of "OriginalImageVector" and values of "NoisyImageVector", the result is same why?</p><p>while when I added slat and pepper noise to the image, it shows some difference between the valuues of "SOriginalImageVector" and "SNoisyImageVector".</p><pre class="language-matlab">IS = imread('barbara.png');
noisyimageS = imnoise(IS, 'salt & pepper', 0.02);
figure; imshow(IS, []);
figure; imshow(noisyimageS, []);
</pre><pre class="language-matlab">s = size(IS);
S = s(1) * s(2);
SOriginalImageVector= reshape(IS, S ,1);
</pre><pre class="language-matlab">s2 = size(noisyimageS);
S1 = s2(1) * s2(2);
SNoisyImageVector= reshape(noisyimageS, S1 ,1);
</pre><p>Kindly explain when we added the Random Value Impulse noise to an image then how we can generate labels?</p><p>(in the slat & pepper noise case, I compared the noisy image values with the original image values and got the labels)</p><p>Random Value Impulse noise added to every pixel ?.</p>shafaq nisarhttps://in.mathworks.com/matlabcentral/profile/authors/8934788-shafaq-nisartag:in.mathworks.com,2005:Question/3422632017-05-28T14:34:57Z2017-05-28T14:44:26ZError: Function definitions are not permitted in this context.<p>I want to design raised cosine pulse modulation code but this error keep coming up.</p><pre> function result = rcp(alpha, t, W)
↑
Error: Function definitions are not permitted in this context.</pre><p>My source code:</p><pre> %rcp.m
function result = rcp(alpha, t, W)
%Raised cosine function in time domain
result = sinc(2*W*t).*cos(2*pi* alpha*W*t)./(1-16*alpha^2*W^2*t.^2);
%Command line
t=[-3:0.001:3];
plot(t,rcp(0.9999,t,1)) %alpha = 1, W = 1
hold on;
plot(t,rcp(0.5,t,1), '--r') %alpha = 0.5, W = 1
plot(t,rcp(0.25,t,1), ':') %alpha = 0.25, W = 1
legend('₩alpha=1','₩alpha=0.5','₩alpha=0.25')
ylabel('pulse amplitude')
xlabel('t/T')
axis([-3 3 -0.25 1])
grid on
title('Raised-cosine pulses in time domain')</pre>Soobin Choihttps://in.mathworks.com/matlabcentral/profile/authors/10391346-soobin-choitag:in.mathworks.com,2005:Question/3422592017-05-28T14:05:12Z2017-05-28T14:38:04Zbetter visualization of quiver()<p>Hello!</p><p>I have some velocity-field, which I am trying to visualize by this code:</p><pre class="language-matlab">quiver(x,y,Vx,Vy);
</pre><p>Vx and Vy are arrays of 102x102 demensions.
It all worked, but I get this:</p><img src = "/matlabcentral/answers/uploaded_files/78972/%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA.JPG"><p>If maximaze it by 8 and zoom to right up corner then the field seems to be possible to analyze:</p><img src = "/matlabcentral/answers/uploaded_files/78973/%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA1.JPG"><p>So, how to spread evenly it all on coordinate plane, how to make arrays less and increase distance between them in order to achieve better understanding of the whole picture at once?</p><p>Thank you in advance!</p>Ivan Volodinhttps://in.mathworks.com/matlabcentral/profile/authors/9784609-ivan-volodintag:in.mathworks.com,2005:Question/3422622017-05-28T14:33:52Z2017-05-28T14:33:52ZHow can I find the density of an object in an image?<p>I have an image of a cell. Inside it there are a lot of small organelles. I want to find out how close are they to each other, some kind of density measure but not exactly. I want to find the nearest neighbor to every organelle. I tried to use BWdist but it measure distance between pixels and in my image - not every organelle equals one pixel. do you have any ideas how to measure this?
in the attached image - I want to look only at the small black dots and to find out how far are they from each other</p><p>thank you for your help!</p>Noy Daninohttps://in.mathworks.com/matlabcentral/profile/authors/10396110-noy-daninotag:in.mathworks.com,2005:Question/3422562017-05-28T13:40:36Z2017-05-28T14:32:20ZHow to create a standalone app with an excel template and how write my result into this template. <p>I would like to create standalone app with an excel template. After computation of raw data, this app has to write result into above template and it has to prompt a message save as option for end user, automatically. Is it possible ?, if so please help me in this regard. thank u in advance.</p>VASUDEVA REDDY RAVURUhttps://in.mathworks.com/matlabcentral/profile/authors/10387394-vasudeva-reddy-ravurutag:in.mathworks.com,2005:Question/3422612017-05-28T14:29:08Z2017-05-28T15:07:41ZCan I use L1-Optimization to estimate a linear set of equations?<p>I have a linear equation Bx=P. Where B is an overdetermined matrix (M x N, M > N), x is a variable column vector, and P is the measurement vector but P has a number of bad data.
My question is: can I use L1-optimization to estimate x? Are there multiple solutions?
Thanks a lot.</p>Benson Gouhttps://in.mathworks.com/matlabcentral/profile/authors/4652929-benson-goutag:in.mathworks.com,2005:Question/3422572017-05-28T13:45:08Z2017-05-28T14:14:54ZExport of Cell-Arrays to more than one txt-file<p>Have a Cell Array XX with the dimension of 31 * 10 and each XX{i,j} consists of 1000 rows and 31 columns. These 1000 lines and 31 columns should end up in a respective txt-file.</p><p>For this I have tried to:</p><pre class="language-matlab">save(file_name_xc,'XX','-ascii');
</pre><pre class="language-matlab">header = '%alb_newsnow alb_oldsnow alb_decrease alb_firn alb_ice alb_shallowpack_ice alb_shallowpack_rock crit_swe_newsnow crit_swe_shallowpack snow_cf temp_wetbulb_lthr temp_wetbulb_uthr clmaxn slope_min slope_max slope_cf curv_max cwh_snow cwh_firn cch refree n_snow k_snow n_firn k_firn n_ice k_ice n_rock k_rock n_soil k_soil';
</pre><pre class="language-matlab">formattype = '' ; for i=1:M-1; formattype = [ formattype '%g\t' ]; end; formattype = [ formattype '%g\n' ];
% open the file with status write
fid = fopen(file_name_xc,'w') ;
% write the header
fprintf(fid,'%s\n',header);
% write -> cell-string
[nrows,ncols] = size(XX);
for row = 1:nrows
fprintf(fid,formattype,XX);
end
</pre><pre class="language-matlab">fclose(fid);
</pre><p>The following error message appeared:</p><p><b>Warning: Attempt to write an unsupported data type to an ASCII file.
Variable 'XX' not written to file.
> In write_to_file at 209</b></p><p>Line 209 includes the code save(file_name_xc,'','-ascii).</p><p>Based on this, I tried to convert the cell-array into a matrix before I used the save(...), with</p><pre class="language-matlab">XX = cell2mat(XX);
</pre><p>In this case, all rows and columns are written to a single matrix and to a single txt file.</p><p>How can one write each XX {} into a separate txt-file, which consists of 1000 lines and 31 columns?</p><p>Thanks</p>Glaziohttps://in.mathworks.com/matlabcentral/profile/authors/3394266-glaziotag:in.mathworks.com,2005:Question/27582011-03-08T17:10:36Z2017-05-28T14:13:10ZPV module simulation<p>Which toolbox i will be used in PV module simulation?</p>Nunohttps://in.mathworks.com/matlabcentral/profile/authors/2772790-nunotag:in.mathworks.com,2005:Question/3411142017-05-20T15:07:39Z2017-05-28T13:41:52ZCheck the number of input arguments of a function<p>Hey there,
Im stuck on a question asking me to check the number of input arguments of a function written by me. It requires to check that the number of inputs are exactly n otherwise the function returns an error message. How do I write a code to achieve that?(No loops plz) And how do I make the function to display an error message? Thanks for answering!!</p>Griffith Wuhttps://in.mathworks.com/matlabcentral/profile/authors/10135995-griffith-wutag:in.mathworks.com,2005:Question/3422552017-05-28T13:02:54Z2017-05-28T13:02:54ZHow do I remove short-selling constraints from a portfolio?<p>I need to calculate an efficient frontier for a Markowitz portfolio using the integrated Portfolio class. If I use the function "setDefaultConstraints", I set short-selling restrictions. The only restriction I need is that the portfolio weights sum to one, how can I thus removed the short-selling restriction? I have tried to "setBounds", but it is not possible to use infinite bounds.</p>MLBhttps://in.mathworks.com/matlabcentral/profile/authors/10216130-mlbtag:in.mathworks.com,2005:Question/3422332017-05-28T06:39:20Z2017-05-28T12:57:18ZI've trained classification learner to classify images into true and false detection.On generating the code for that classifier and using the prediction function to classify new images,I keep getting all of them as true. What can be the reasons? <p>This is a part of the code I have written:</p><p>yfit = trainedClassifier.predictFcn(test);
p=1;
for i=1:m
if(yfit(i,:)=='TP');
index(p)=i;
p=p+1;
end
end</p><p>%%
n=length(index);
for b=1:n
bbox1(b,:)=bbox(index(b),:)
end</p><p>detectedImg1=insertObjectAnnotation(i1,'rectangle',bbox1,'wr');
figure;
imshow(detectedImg1);</p><p>On executing yfit has all values as TP. So every initial bounding boxes are again considered in the final image when I want to exclude the false detections.</p>Ankita Mohantyhttps://in.mathworks.com/matlabcentral/profile/authors/10394661-ankita-mohantytag:in.mathworks.com,2005:Question/3339652017-04-06T08:49:29Z2017-05-28T12:52:08ZSource code for multi hop LEACH protocol in wireless sensor networks<p>Source code for multi hop LEACH protocol in wireless sensor networks</p>Sunil Kumar Patelhttps://in.mathworks.com/matlabcentral/profile/authors/9255406-sunil-kumar-pateltag:in.mathworks.com,2005:Question/3422492017-05-28T11:07:46Z2017-05-28T12:47:13Zfast solution for matrix multiplication<p>I have the following expression of the matrix elements B_(l,m):</p><p>B_(l,m)=Sum(over k=0 to N) of a_(l,k)*a_(m,k+1)+a_(l,k+1)*a_(m,k);</p><ol><li>N is a number between 10-1000</li><li>a_(l,k) is a matrix of size N*N</li></ol><p>my approach was to go with a loop over the columns of a_(l,k)</p><p>(multiplying each column of a_(l,k) by the entire matrix a_(m,k))</p><pre> for i=1:N
a_lmk=a_lnk(k+1,i).*a_lk(k+2,:)+a_lk(k+2,i).*a_lk(k+1,:);
B_lm(i,:)=sum(a_lmk);
end</pre><p>Is there a direct and faster method to calculate it?</p><p>I'm attaching a picture to clarify the expression (I can handle with the prefactors 2,(k+1)./...).</p>dhttps://in.mathworks.com/matlabcentral/profile/authors/5382698-dtag:in.mathworks.com,2005:Question/2759162016-03-29T05:59:27Z2017-05-28T12:41:03ZHow to get f28377s support packages in simulink library?<p>Sir,
I want to interface my delfino F28377S with matlab but there is no support package available in matlab simulink library even after installing all available c2000 installer packages in matlab2014 and also in 2015. Please suggest me a solution to this issue.</p>amin khatrihttps://in.mathworks.com/matlabcentral/profile/authors/7063650-amin-khatritag:in.mathworks.com,2005:Question/3422542017-05-28T12:32:45Z2017-05-28T12:32:45ZBootloader code porting for TI C2000 f28379d using simulink<p>Hi all,</p><pre class="language-matlab">Currently working on bootloader porting.
Initial requirement is to port hand written bootloader code of C2000 TMS320F28335(Developed using ccsv6) custom board to C2000 TMS320F28379D launchpad or control card, later it may port to f28379d custom board.
</pre><p>1. Is it possible to impliment above requirment using Matlab simulink?? Pleae clarify.
2. If so, can be possible using below tools, please clarify.
Matlab R2017a trail use
CCSv7.1.0.16,
Controsuite v3.4.6
C2000Ware_1_00_01_00
3. MatlabR2017a installed on my PC and went through the TI forum link mentioned below,
https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/484814#pi316717=6
But not able to install the c2000 add on hardware package support,
error is support package requires the Embedded Coder 6.12, the package can we get for trail use, please clarify?
4. Is there any other Mathworks tools are required?</p><p>Thanks in advance</p>kakhttps://in.mathworks.com/matlabcentral/profile/authors/10390155-kaktag:in.mathworks.com,2005:Question/3422352017-05-28T06:57:23Z2017-05-28T12:31:09ZSteps for estimating alpha in 1/f^alpha noise using OLS<p>I have a signal (the vector "pink"), which I know is pink noise, 1/f^alfa, where alpha = 1. But let's assume alpha is unknown, and I need to estimate alpha. In other words, Let's assume I just have the signal.</p><p>I use the following procedure to get into a position to estimate alpha using OLS:</p><p>F = abs(fft(pink));
x = log(1:(length(pink)/2));
y = log(F(1:(length(pink)/2)));</p><p>Now I run OLS regression:</p><p>[r,m,b] = regression(x,y)</p><p>where I get</p><p>r = -0.5948,
m = -0.4915,
b = 6.8223.</p><p>I would have thought my estimate of alpha was m, but m is not equal to 1. So, what am I doing wrong? Is there an additional step I am forgetting, or is my procedure plain wrong?</p>Ulrik William Nashhttps://in.mathworks.com/matlabcentral/profile/authors/6347121-ulrik-william-nashtag:in.mathworks.com,2005:Question/3422012017-05-27T19:47:44Z2017-05-28T12:29:30ZHow would I go about adding these scales to my figure? <p>I have the first image, but need to apply the scale that is visible in the next image. How might I go about this? Could you please just point me in the right direction? Thank You.</p><img src = "/matlabcentral/answers/uploaded_files/78932/Amplitude2.0.jpg"><img src = "/matlabcentral/answers/uploaded_files/78933/Amplitude2.jpg">Isaiah Stefan Englehttps://in.mathworks.com/matlabcentral/profile/authors/8827749-isaiah-stefan-engletag:in.mathworks.com,2005:Question/3422432017-05-28T08:13:35Z2017-05-28T12:22:22ZHow can i crop multiple images<p>Hello,
I have, with the help of regionprops, drawn a bounding box around the parts I would like to crop. Could anyone tell me how i can crop the images and store it.
Thank you.
Edit: I am trying to crop handwritten characters.</p>shru shttps://in.mathworks.com/matlabcentral/profile/authors/10371273-shru-stag:in.mathworks.com,2005:Question/3422462017-05-28T10:26:26Z2017-05-28T12:05:27ZHow can i seprate foreground object i.e. Human from background in a static image?<p>i have to seprate foreground object i.e. Human from background in a static image....can anyone guide me towards a good algorithm.</p><img src = "/matlabcentral/answers/uploaded_files/78966/87.jpg">Maria Alihttps://in.mathworks.com/matlabcentral/profile/authors/10395326-maria-ali