https://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-02-17T23:38:38Ztag:nl.mathworks.com,2005:Question/3832452018-02-17T15:35:51Z2018-02-17T23:38:38Zway to make animation faster?<p>I'm trying to have an animation of my equation over time. My code technically works, but it is super slow. It seems like it is because my equation requires a summation over a lot of n values while also needing a lot of points between the limits on the x-axis and a lot of time steps. Any ideas on what I can do to make this run like a smooth animation?</p><pre class="language-matlab">syms n
a = 4;
x = linspace(0,4,50);
for t = 0:0.1:20
Psi = symsum(((2/pi) .* sqrt(2/a) .* (1/n) .* ((cos((n.*pi)./4) - cos((n.*3.*pi)./4))) * sin((n.*pi.*x)./a) * exp(-1i*((pi^2 * n^2)/(32))*t)),n,1,100);
plot(x,Psi);
axis([0 4 -1 1])
drawnow
end
</pre>Brandon Bellhttps://nl.mathworks.com/matlabcentral/profile/authors/7649419-brandon-belltag:nl.mathworks.com,2005:Question/3832162018-02-17T11:27:06Z2018-02-17T23:37:10Zhow can i draw circle in 3D space with 3 point ?<p>Dear all</p><p>I need to draw a circle in space with 3 points that I have.</p><p>For example in the picture below I need to through the circle among the purple orange and the yellow dots.</p><img src = "/matlabcentral/answers/uploaded_files/105152/untitled.jpg"><p>and the arrays are :</p><pre class="language-matlab">% for yellow dots :
x=[0.0614989006404664,0.113882215391292,0.150982198682794,0.168720920205744];
y=[0.00968012746750092,0.0348743496847940,0.0721490692945351,0.117011183107267]
z=[0.00433547467220984,-0.0182991382514783,-0.0513287453937180,-0.0902019922333220]
</pre><pre class="language-matlab">% for purple dots :
x=[0.0538953885999417,0.100380017854628,0.133603344329503,0.149651163313763]
y=[0.0181936243771012,0.0397661500353233,0.0724936983973233,0.112238051664588]
z=[-0.0140617255229237,-0.0345013279495237,-0.0642363653195066,-0.0992745656450756]
</pre><pre class="language-matlab">% for orange dots :
x=[0.0601617429784619,0.112244770523508,0.149580182011997,0.167771471007159];
y=[-0.00252268954107996,0.0216775496992773,0.0583666486260463,0.102963217155185]
z=[-0.0134985732822516,-0.0353846070611784,-0.0679669312855640,-0.106648973683681]
</pre>shahin hashemihttps://nl.mathworks.com/matlabcentral/profile/authors/11613864-shahin-hashemitag:nl.mathworks.com,2005:Question/3832872018-02-17T23:35:36Z2018-02-17T23:35:36ZHow to record the name of an image?<p>I would like to save in Excel, the name of the image I load. Can someone help me? How can I do it? Please</p>Catarina Leitãohttps://nl.mathworks.com/matlabcentral/profile/authors/12153163-catarina-leitaotag:nl.mathworks.com,2005:Question/920482011-04-29T14:09:00Z2018-02-17T23:34:00ZHow do I launch or Start MATLAB?<p>How do I launch or Start MATLAB?</p>MathWorks Support Teamhttps://nl.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:nl.mathworks.com,2005:Question/2339282015-08-14T19:16:49Z2018-02-17T23:27:52ZMATLAB Answers Wish-list #4 (and bug reports)<p>This topic is for features you would like to see for the MATLAB Answers facility itself, and also for bug reports about the MATLAB Answers facility.</p><p>This topic is the follow on to the first <a href = "http://www.mathworks.com/matlabcentral/answers/994">Wish-list for MATLAB Answer sections</a> and second <a href = "http://uk.mathworks.com/matlabcentral/answers/42413-matlab-answers-wish-list-2-and-bug-reports">MATLAB Answers Wish-list #2 (and bug reports)</a>. Those grew large enough to become unwieldy; and Mathworks has made enough changes to make a number of the past points no longer of relevance. More recently there was the limited purpose <a href = "http://uk.mathworks.com/matlabcentral/answers/216662-new-design-of-the-forum-grey-on-white-wish-list-3-bug-reports">New design of the forum - grey on white</a> which turned into a bug and wish list; I have renamed that for continuity.</p><p>I suggest one wish (or bug report) per answer, so that people can vote their wishes.</p>Walter Robersonhttps://nl.mathworks.com/matlabcentral/profile/authors/434782-walter-robersontag:nl.mathworks.com,2005:Question/3811992018-02-07T01:01:45Z2018-02-17T23:21:51Z#Define Preprocessor statements in Simulink Library File<p>After reading this mathworks support article, I would like to apply this to a set of Simulink Libraries:</p><p>https://www.mathworks.com/matlabcentral/answers/184184-how-do-i-make-sure-simulink-constants-are-coded-as-define</p><p>However, it seems that libraries do not have options that this article points to (at least I cannot find them). Is there a way in the model explorer to define a custom type that creates a #define statement with a constant that generates to C code with a preprocessor #define statement?</p>DKalalehttps://nl.mathworks.com/matlabcentral/profile/authors/4330645-dkalaletag:nl.mathworks.com,2005:Question/3832442018-02-17T15:30:58Z2018-02-17T23:20:53ZHistogram struggles (excluding low values and multiplying all the data)<p>Hi,</p><p>I’m trying to make histogram out of some data</p><pre class="language-matlab">lc = cellfun(@(c) c(end,6),particles);
hist(lc, 20)
</pre><p>How do I exclude values lower than 2 from the histogram? (as this back ground noise and looks messy)</p><p>ALSO - the data is current in the wrong units and I would convert it by multiplying by 7.431 (for example)</p><p>So to apply this to the data in the histogram would I do:</p><pre class="language-matlab">lc = cellfun(@(c) c(end,6),particles)
f=lc*7.431
hist(f,20)
</pre><p>Thanks in advance :)</p>Saskia Davishttps://nl.mathworks.com/matlabcentral/profile/authors/11022824-saskia-davistag:nl.mathworks.com,2005:Question/3832632018-02-17T18:10:42Z2018-02-17T23:11:36ZConstraints not satisfied with 'ga' solver and integer variables <p>Hi all,</p><p>I've been struggling to understand what is the problem with my code. I wrote this long time ago, and now I'm using it with another dataset (large one) and is not working. I'm using 'ga' optimisation with integer variables, but I'm getting the legend of " <i>Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance but constraints are not satisfied.</i>"</p><p>Basically what I want to do with my constraints is to avoid repetitions of the integer values in the vector of variables "x" (which has 42 values), and to make sure that the integer value selected for each "x" exists in the respective column of a matrix (124 rows, 42 columns). My LB and UB are between 1 to 124.</p><p>The results that I'm getting for the vector "v" are either very close to LB or UB, so 1 to 4 and 122 to 124. So I'm thinking that maybe is completely ignoring all the integer numbers and that's why it cannot find a solution. Here are the line where I call the ga:</p><pre class="language-matlab">x = [55 96 33 73 4 51 37 39 50 78 20 88 1 47 17 44 40 66 56 113 74 31 105 34 108 65 49 8 75 22 99 42 91 46 93 71 82 121 94 114 48 70];
LB=ones(1,42);
UB=zeros(1,42); UB(:)=124;
IntCon=[1:1:42];
hj=72;
options=optimset('Display', 'iter', 'FunValCheck', 'on');
[ x, fval, exitflag] = ga(@(x) ObjFun(x,TwoVal,distances, indices00,OrderedVal,hj,dimension00),42,[],[],[],[],LB,UB,@(x) constGa(x,OrderedVal),IntCon, options);
</pre><p>And the constraint function:</p><pre class="language-matlab">function [c,ceq] = constGa(x,OrderedVal)
ceq=[];
c1=length(unique(x)) == length(x);
c1=double(c1);
c1=(c1-1).^2;
ee=length(x);
for xe=1:ee
c2(xe)= ~ismember(x(xe),OrderedVal(:,xe));
end
c2=double(c2);
c2=sum(c2);
c=[c1;c2];
</pre><p>If you have an idea what I might be doing wrong, I appreciate your suggestions. When I run this in a smaller dataset of 5 "x" variables instead of 42, and LB and UB between 1 to 18 instead of 1 to 124, I get a solution with satisfied constraints and minimum objective function.</p><p>Thank you,
Martha</p>Marthahttps://nl.mathworks.com/matlabcentral/profile/authors/4934229-marthatag:nl.mathworks.com,2005:Question/3832862018-02-17T23:10:33Z2018-02-17T23:10:33ZHow to Resize Images in ImageDatastore<p>I'm trying to resize several images from a file folder that I put into an ImageDatastore. The example code on Mathworks is the following:</p><p>imds.ReadFcn = @(loc)imresize(imread(loc),inputSize);</p><p>What is meant by loc? I assumed location but I'm getting errors. Or does this mean I need to make my own function and then call it in my script? Thank you.</p><p><a href = "https://www.mathworks.com/help/nnet/ug/preprocess-images-for-deep-learning.html#mw_415221ea-4a60-40b2-81bf-281f41ebd2be">https://www.mathworks.com/help/nnet/ug/preprocess-images-for-deep-learning.html#mw_415221ea-4a60-40b2-81bf-281f41ebd2be</a></p>Jazmine Covarrubiashttps://nl.mathworks.com/matlabcentral/profile/authors/8389319-jazmine-covarrubiastag:nl.mathworks.com,2005:Question/3832802018-02-17T20:11:17Z2018-02-17T23:08:09ZMatrix from results of nested for / if loop? <p>Hi Community!
I am trying to create a matrix from an equation, where one side of the equation is a set value (e.g. 31.5) and the other side is a product of two fractions (see code):</p><pre class="language-matlab">z1low = 17;
%Starting value for z1
z1high = 51;
%Final value for z1
z2low = 17;
%Starting value for z2
z2high = 306;
%Final value for z2
z3low = 17;
%Starting value for z3
z3high = 51;
%Final value for z3
z4low = 17;
%Starting value for z4
z4high = 306;
%Final value for z4
u = 31.5;
%Desired total gearing
</pre><pre class="language-matlab">for z1 = z1low: 1: z1high
for z2 = z2low: 1: z2high
for z3 = z3low: 1: z3high
for z4 = z4low: 1: z4high
if (z2/z1)*(z4/z3) == u
A = {z1, z2, z3, z4};
B = cell2mat(A(1:4));
disp(B)
disp(size(B))
end
end
end
end
end
</pre><p>The above code runs nicely through the for-loops and the if-condition, but it only returns the latest results for the z-values (thus the (1, 4) size of B).</p><p>Is there a simple way in MatLab to add each resulting row of the for/if-loop iteration to the bottom of a matrix?
Thank you very much!</p>Oskar Larssonhttps://nl.mathworks.com/matlabcentral/profile/authors/8608157-oskar-larssontag:nl.mathworks.com,2005:Question/3831932018-02-17T04:42:16Z2018-02-17T22:57:58ZHow to copy files to different folders based on part of filename (strings and numbers)<p>Hi,</p><p>I haven't been able to find a solution to my problem when trying to copy files with similar part of filename, including words and numbers. I have a few thousand files (each file has GB's of data) with names like these:</p><pre> Land_0020_AAAA_VXC_XXXxXX_19910311_19970329_01.51mEa_072414.csv
Land_0075_AAAA_VXC_XXXxXX_19890615_19930119_04.11mEa_052274.csv
Land_0077_AAAA_VXC_XXXxXX_19930611_19970319_11.48mNo_0624394.csv
Land_0079_AAAA_VXC_XXXxXX_19790815_19930109_17.52mFa_0224343.csv
Land_0083_AAAA_XDC_XXXxXX_19930611_19970319_11.38mEa_0644043.csv
Land_0089_AAAA_XDC_XXXxXX_19790815_19930109_19.57mNa_0124343.csv
Land_0120_BBBB_Msx_XXXxXX_19910311_19970329_01.51mEa_07243430.csv
Land_0125_CCCC_PLK_XXXxXX_19890615_19930119_04.11mPa_0522143.csv
Land_0130_BBBB_Msx_XXXxXX_19930611_19970319_11.48mEa_0621713.csv
Land_0137_CCCC_PLK_XXXxXX_19790815_19930109_16.52mNa_0220346.csv
...
Land_8169_ABAB_Mhl_XXXxXX_19800617_19930121_19.32mSa_0227336.csv
...</pre><p>In filenames above, the combination of letters like (AAAA and VXC) and numbers like (01.51) are the key info for my identification before copying files to different folders.</p><p>My main problem in script below is that my statements don’t work as I want…</p><pre> if (Code1 =='AAAA' & Code2='VXC' & Code3 > 0.00 & Code3 <= 4,99 ); …</pre><p>This is the example of my attempt ...</p><pre> cd ..
myFolder = 'A:\..';
filePattern = fullfile(myFolder, '*.csv');
theFiles = dir(filePattern); </pre><pre> FileNames = theFiles;
NumFiles = size(FileNames);</pre><pre> %Loop through files</pre><pre> for ifile=1:NumFiles;
FileTemp=FileNames(ifile).name
Code1 = FileTemp(11:14); %Read AAAA from above first filenames
Code2 = FileTemp(16:18); %Read VXC from above first filenames
Code3 = str2num(FileTemp(45:49)); %Read 01.51 from above first filename
clear FileIwant;
count=0</pre><pre> %STATEMENTS</pre><pre> if (Code1 =='AAAA' & Code2='VXC' & Code3 > 0.00 & Code3 <= 4,99 );
%Create new folder or use existent
aa = fullfile(pwd, [Code1 '_' Code2 '_Land0-4m']); if ~exist(aa, 'dir'); mkdir(aa); end
%Create and copy file that follow statement
FileIwant{count}=FileTemp;
copyfile(char(FileIwant), aa);</pre><pre> elseif</pre><pre> if (Code1 =='AAAA' & Code2='VXC' & Code3 > 5.00 & Code3 <= 9,99 );
%Create new folder or use existent
bb = fullfile(pwd, [Code1 '_' Code2 '_Land5-10m']); if ~exist(bb, 'dir'); mkdir(bb); end
%Create and copy file that follow statement
FileIwant{count}=FileTemp;
copyfile(char(FileIwant), bb);</pre><pre> else</pre><pre> if (Code1 =='AAAA' & Code2='XDC' & Code3 > 10.00 & Code3 <= 14.99 );
%Create new folder or use existent
cc = fullfile(pwd, [Code1 '_' Code2 '_Land10-15m']); if ~exist(cc, 'dir'); mkdir(cc); end
%Create and copy file that follow statement
FileIwant{count}=FileTemp;
copyfile(char(FileIwant), cc);</pre><pre> else</pre><pre> if (Code1 =='AAAA' & Code2='XDC' & Code3 > 15.00 & Code3 <= 20.00);
%Create new folder or use existent
dd = fullfile(pwd, [Code1 '_' Code2 '_Land15-20m']); if ~exist(dd, 'dir'); mkdir(dd); end
%Create and copy file that follow statement
FileIwant{count}=FileTemp;
copyfile(char(FileIwant), dd);</pre><p>%After check that filename has the 4 letters (e.g. AAAA) and the 3 letter %(e.g. VXC) and is in the numerical range between (e.g. 0 to 4.99), then the loop should create a folder (if this doesn’t exist already) and then copy the files that follow the statements. Then move to next statement.</p><p>%Then I need to continue with ‘else’ for all other Code1 and Code2 combinations.</p><pre> count=count+1;</pre><pre> end</pre><p>Thanks for your suggestions!</p>Roberthttps://nl.mathworks.com/matlabcentral/profile/authors/3899707-roberttag:nl.mathworks.com,2005:Question/3832832018-02-17T21:45:56Z2018-02-17T22:55:21Zhow to print a matrix as ranked sorted list?<p>if I have this matrix [56 9 8 7 4 5 6 3 35 4 ]
How to print is as</p><p>Rank Score</p><p>1 56.00</p><p>2 35.00</p><p>3 9.00</p><p>4 8.00</p><p>5 7.00</p><p>6 6.00</p><p>7 5.00</p><p>8 4.00</p><p>9 4.00</p><p>10 3.00</p>sami Alqahtnaihttps://nl.mathworks.com/matlabcentral/profile/authors/12137076-sami-alqahtnaitag:nl.mathworks.com,2005:Question/3832432018-02-17T15:28:13Z2018-02-17T22:39:52ZHow do I make a 2D randomwalk?<p>I have so far only been able to make a 1D randomwalk but I have to make it into 2D. Below is my code for 1D. How do I change it so that it is in 2D?</p><pre> clear
clc</pre><pre> N = 100; % Length of the x-axis, also known as the length of the random walks.
M = 400; % The amount of random walks.
x_t(1) = 0;</pre><pre> for m=1:M
for n = 1:N % Looping all values of N into x_t(n).
A = sign(randn); % Generates either +1/-1 depending on the SIGN of RAND.
x_t(n+1) = x_t(n) + A;
end
plot(x_t);
hold on
end</pre>Delshad Ayoubihttps://nl.mathworks.com/matlabcentral/profile/authors/10838708-delshad-ayoubitag:nl.mathworks.com,2005:Question/3831112018-02-16T15:54:34Z2018-02-17T22:28:14ZHow do I call a saved file in Raspberry pi into my simulink stand alone code running in the Raspberry pi?<p>Hey
So I have a simple simulink code that takes a .mat file as an input and displays a graph. I now have deployed the Simulink code in the raspberry pi. I have put a .mat file in raspberry pi using putFile(rpi,' ') . I want to call this file in my simulink code , which is already deployed in raspberry pi and run it(using sudo ./modelname.elf ) and then get its data to my computer using getFile command. But I am unable to call this file to my simulink code. I was using the To File block for the computer simulations but inorder to run the standalone file saved in raspberry pi,I cannot seem to do so.</p>Prakhar Kumarhttps://nl.mathworks.com/matlabcentral/profile/authors/10742492-prakhar-kumartag:nl.mathworks.com,2005:Question/3829472018-02-15T19:34:29Z2018-02-17T22:25:44ZUse retime() to resample to fractional seconds? <p>Timetables look to be very flexible, but I have data timed to msecs and would like to resample to some higher fractional second rate, such as 0.1 sec. Is there any way to use retime to do that? It appears retime may be limited to 1 second in resolution.</p>RonM64https://nl.mathworks.com/matlabcentral/profile/authors/161342-ronm64tag:nl.mathworks.com,2005:Question/3832852018-02-17T22:23:14Z2018-02-17T22:23:14Zneed help on satellite communication<p>Hi i am postgraduate student and would like to simulate Broadband over satellite. This simulation related to attenuation (weather) and downlink it via antenna on moving object e.g car (speed & vibration).
Kindly assist on which Simulink that i need to use. Since i unable to find any.
Thanks</p>kalai vaananhttps://nl.mathworks.com/matlabcentral/profile/authors/12183170-kalai-vaanantag:nl.mathworks.com,2005:Question/3831502018-02-16T19:29:49Z2018-02-17T22:18:08ZHow to convert a cell array into a datetime array<p>I have a 29 x 1 cell array which contains 29 1 x 1 datetime variables.
I wish to plot the 29 values as an x axis, but am unable to as Matlab registers them as an array of cells instead of date times. Can this be converted? Thanks!</p>Megan Adamshttps://nl.mathworks.com/matlabcentral/profile/authors/11852333-megan-adamstag:nl.mathworks.com,2005:Question/3829362018-02-15T18:15:30Z2018-02-17T22:12:21Zsegregate table in mat lab<p>hi I have the following table in mat lab.</p><img src = "/matlabcentral/answers/uploaded_files/104934/1_tableGlobal.png"><p>I want to create a procedure or function in mat lab so as I can loop through the mention table and segregate it into two tables:</p><p>First one contains all information for the station LR as shown below</p><img src = "/matlabcentral/answers/uploaded_files/104935/2_tableLR.png"><p>Secon one contain all information for the staionn LZ as shown below</p><img src = "/matlabcentral/answers/uploaded_files/104936/_tableLZ.png"><p>Anyone can help me to do this algorithm will be appreciate</p><p>Regards.</p>wissam abdallahhttps://nl.mathworks.com/matlabcentral/profile/authors/12154081-wissam-abdallahtag:nl.mathworks.com,2005:Question/3829462018-02-15T19:21:39Z2018-02-17T22:09:58ZHow can I expand a table row variable array into multiple table rows<p>I have a table, something like this trivial example:</p><pre class="language-matlab">s(1).id="a"; s(1).datatype="this";s(1).val=zeros(34,1);
s(2).id="b"; s(2).datatype="that";s(2).val=zeros(12,1);
s(3).id="c"; s(3).datatype="other";s(3).val=zeros(42,1);
T=struct2table(s)
</pre><pre class="language-matlab">3×3 table
</pre><pre> id val datatype
___ _____________ ________</pre><pre> "a" [34×1 double] "this"
"b" [12×1 double] "that"
"c" [42×1 double] "other" </pre><p>I would like to expand the table such that the first row would expand to 34 rows, each with a successive value from the val table variable for the original row. I would end up with a table with 34+12+42 rows.</p><p>I've tried doing this with a split apply on the table, grouping into the datatype variable, but ultimately I'm iterating through the table and it's slow, on the order of 20 minutes for a table of 70K rows. It seemed that rowfun() would also be slow because it's also iterating through the table. I was wondering if there is some faster way to perform this operation.</p><p>Ultimately what I'm trying to do is treat the val variable in my trivial example as a date time value and then generate a timetable using the date times as the row times, in case that makes any difference.</p>Ron Cordellhttps://nl.mathworks.com/matlabcentral/profile/authors/11209222-ron-cordelltag:nl.mathworks.com,2005:Question/3832842018-02-17T22:04:07Z2018-02-17T22:05:07ZError using spline : data site should be distinct<p>t= 0:5e-12:10e-9;</p><p>LR_V=zeros(NO,num_nodes_LR,length(t));</p><p>for j=1:num_nodes_LR</p><pre> W = vals(j,1);</pre><pre> ht = vals(j,2);</pre><pre> T = vals(j,3);</pre><pre> d = vals(j,4);</pre><pre> Er = vals(j,5);</pre><p>TL_EX_16(vals(j,:));</p><pre> x=loadsig('C:\Research_Data\Jr2\example1\TL_EX_16.tr0');</pre><pre> tp = evalsig(x,'TIME');</pre><pre> V_C1 = evalsig(x,'v_17');</pre><p>LR_V(1,j,:) = spline(tp,V_C1,t);</p><p>j</p><p>end</p>ADhttps://nl.mathworks.com/matlabcentral/profile/authors/11165576-adtag:nl.mathworks.com,2005:Question/3830262018-02-16T06:15:21Z2018-02-17T22:01:56ZProblem when using imwrite ...<p>%The directory where the image will be saved</p><pre class="language-matlab">folder = '\Users\public\Documents\MATLAB\faceBank';
name = strcat(Rnombre,Rapellido,Rcargo,'.jpg');
</pre><p>%Are attributes of which the file name will be composed</p><pre class="language-matlab">imwrite(work_area,fullfile(folder,name));
work_area is the variable that contains the image
</pre><p>i have this error</p><pre class="language-matlab">Error using imwrite>parse_inputs (line 510)
A filename must be supplied.
</pre><pre class="language-matlab">Error in imwrite (line 418)
[data, map, filename, format, paramPairs] = parse_inputs(varargin{:});
</pre>Alfredo Torres Arceohttps://nl.mathworks.com/matlabcentral/profile/authors/11331569-alfredo-torres-arceotag:nl.mathworks.com,2005:Question/3130122016-11-19T11:48:59Z2018-02-17T22:00:44ZHow concatenate two tables in MATLAB?<p>I have two tables with no variables in common, with the same number of rows and with different number of columns. For example:</p><pre> Age Height
___ ______
38 71
43 69 </pre><p>and the table:</p><pre> Weight Blood
______ ______
176 124
163 109 </pre><p>How can I get:</p><pre> Age Height Weight Blood
___ ______ ______ _____
38 71 176 124
43 69 163 109 </pre><p>Thanks!</p>Adrianohttps://nl.mathworks.com/matlabcentral/profile/authors/5461029-adrianotag:nl.mathworks.com,2005:Question/3832522018-02-17T16:13:25Z2018-02-17T21:58:33ZGood afternoon. Please I need help. I have my data arrange as (Lat Lon Z) on a regular grid. I want to used this data on regular grid to plot contour without any interpolation of any kind. How do i do it and how best can I arrange my data. Thank you<p>Good afternoon. Please I need help. I have my data arrange as (Lat Lon Z) on a regular grid. I want to used this data on regular grid to plot contour without any interpolation of any kind. How do i do it and how best can I arrange my data. I have been trying so many function for the past three months but nothing work. Thank you as you save me from ignorance.</p>Abimbola Ayenihttps://nl.mathworks.com/matlabcentral/profile/authors/10432135-abimbola-ayenitag:nl.mathworks.com,2005:Question/3832172018-02-17T11:31:05Z2018-02-17T21:54:15Zsplit table in mat lab with respect to row values<p>Hi
i try to write script in matlab so as i can split my table in many others tables. my script return an error mentioned in the following picture which also clarify all my workspace and the description of my table(climSumry):</p><img src = "/matlabcentral/answers/uploaded_files/105156/5_climTable_Summary_algo.png"><p>any one can help me to find where is the error in my script and how i should correct it ?? thank you.
Regards</p>wissam abdallahhttps://nl.mathworks.com/matlabcentral/profile/authors/12154081-wissam-abdallahtag:nl.mathworks.com,2005:Question/3832782018-02-17T19:44:44Z2018-02-17T21:42:15ZAdd newer data to older data without repetition<p>Imagine 2 two datasets where column 1 is a timestamp, column 2 is data (can be more columns).</p><p>Yesterday i had this:</p><pre class="language-matlab">A = [ 1 2 3 4 5 6 7 ; 435 124 525 342 532 533 213 ]'
</pre><p>Today I get this (Rows each day can vary):</p><pre class="language-matlab">B = [ 5 6 7 8 9 10 ; 532 533 213 988 999 777 ]'
</pre><p>So 5:7 (timestamp) overlaps. Any idea how I can end up connecting those time stamps so I can get this:</p><pre class="language-matlab">C= [ 1 2 3 4 5 6 7 8 9 10 ; 435 124 525 342 532 533 213 988 999 777]'
</pre><p>I want to return all the data in A and B without repeating the data common to both A and B (not just simple concatinating)</p><p>Thanks in advance</p>Martinhttps://nl.mathworks.com/matlabcentral/profile/authors/4265483-martintag:nl.mathworks.com,2005:Question/3575822017-09-20T15:03:19Z2018-02-17T21:41:57ZAutomatic Transfer Switch Model<p>Hello,</p><p>I'm on a masters programme at University and I'm currently on a placement where I have been asked to model an Automatic Transfer Switch (both opened and closed) to be included in a larger simulation model of a Renewables Microgrid.</p><p>I've been stuck on this component for a while as I can't find much resources on the Transfer Switch relevant to Matlab and, due to legal reasons between the company I am on placement at and the Engineering Consultancy that installed the microgrid, I don't have access to the schematics for each of the components.</p><p>If anyone has constructed or seen a similar model or set of schematics which could be relevant to my research, or if they know of any block in Simulink that may be relevant, or if they just have any general advice which may be of some help, I would very much appreciate it.</p><p>If any of you have any questions that you would want to ask me to broaden your understanding of my problem, just ask and I'll try my best to make better sense of it.</p><p>Thanks so much!
Ali.</p>Alasdair Robertsonhttps://nl.mathworks.com/matlabcentral/profile/authors/10564007-alasdair-robertsontag:nl.mathworks.com,2005:Question/3832092018-02-17T08:37:40Z2018-02-17T21:39:03ZHow to determine the first five positive inputs and add the five inputs? <p>Since its 15 inputs all i put it in matrix .</p><pre class="language-matlab">A=[a, b, c; d, e, f; g, h, i; j, k, l ;m, n, o]
C=gsort(A)
D= C(15,:) + C(14,:) + C(13,:) + C(12,:) + C(11,:)
</pre><p>Help. I don't know what I'm doing.</p>Jel Marshallhttps://nl.mathworks.com/matlabcentral/profile/authors/12179970-jel-marshalltag:nl.mathworks.com,2005:Question/3832252018-02-17T12:10:38Z2018-02-17T21:19:57ZHow to compute Ergodic channel capcity as a function of number transmit antenna<p>How can I compute the channel capacity C as a function of K (K changes from 2 to 16) averaged over 1000 iterations based on the equation.
C = E[log2(det(I_M + roh*H'DH))]
where
D = (1/K)I_K, (I_K is an identity matrix of dimension KxK)
roh = 10dB,
I_M is an identity matrix = I_K.
C was supposed to be a row vector of size 1x16 but I was getting a 1x1 dimensional matrix.</p><pre class="language-matlab">clear; close all; clc;
M = 2:16;
K = 2:16;
N = 1000;
roh = 10;
</pre><pre class="language-matlab">for ii = K
I_M = eye(ii);
D = (1/ii) * I_M;
H = 1/sqrt(2) * (randn(ii,ii) + 1i * randn(ii, ii));
C = mean(log2(det(I_M + roh * H'* D * H)));
</pre><pre> C_sum = 0;
for k = 1:N
C_sum = C_sum + C;
end
end</pre>ABDULLAHI MOHAMMADhttps://nl.mathworks.com/matlabcentral/profile/authors/12148701-abdullahi-mohammadtag:nl.mathworks.com,2005:Question/3832722018-02-17T19:05:18Z2018-02-17T21:14:32ZI can't seem to find the error in my program.<p>My program looks like this, its supposed to take the input signal and output signal after convolution and graph them versus a variable.</p><pre class="language-matlab">function graphconv(~)
L=200;
K=50;
n=0:L-1;
z = double(rem(n,K) < K/2);
h=@(n) 1/15 .* n>=0&&n<=14;
y = conv(h,z);
plot(n,z,'r',n,y,'b')
</pre><p>but i keep getting these errors and i can't seem to understand what they mean. I already tried googling it but to no avail.</p><p>ERROR CODES:</p><pre class="language-matlab">>> graphconv
</pre><pre class="language-matlab">Input arguments to function include colon operator. To input the colon character,
use ':' instead.
</pre><pre class="language-matlab">Error in conv (line 43)
c = conv2(a(:),b(:),shape);
</pre><pre class="language-matlab">Error in graphconv (line 11)
y = conv(h,z);
</pre>Santos Tapiahttps://nl.mathworks.com/matlabcentral/profile/authors/9633115-santos-tapiatag:nl.mathworks.com,2005:Question/3832652018-02-17T18:14:44Z2018-02-17T21:08:19ZDriving Audio Device in Simulink Desktop Real-time <p>The Audio Writer block does not work in External Mode with Desktop Real-Time.</p><p>Is there a way to drive the audio output otherwise for Desktop Real-time?</p>Spencer Chenhttps://nl.mathworks.com/matlabcentral/profile/authors/8504792-spencer-chentag:nl.mathworks.com,2005:Question/2991692016-08-10T18:09:56Z2018-02-17T21:06:39ZAutomatically generate program logic flow chart from mfile?<p>I just discovered <a href = "http://code2flow.com/#">code2flow</a> which is great for mapping out the logical flow of code, for example when debugging. However it requires you enter pseudo code, or you can run it on existing javascript or Python code. I would love if there was a similar tool that would let you make a visual representation of the logic flow of an mfile. Does this exist?</p>K Ehttps://nl.mathworks.com/matlabcentral/profile/authors/1596298-k-etag:nl.mathworks.com,2005:Question/3832692018-02-17T18:41:50Z2018-02-17T20:58:36ZHow extract skull ?<p>how to extract the skull from the brain (other than the thresholding method) ?</p>marwa zahttps://nl.mathworks.com/matlabcentral/profile/authors/6314589-marwa-zatag:nl.mathworks.com,2005:Question/3832332018-02-17T13:12:07Z2018-02-17T20:56:53Z(Anti)diagonal automation<p>Counting from the top right element to the the bottom left element of an indicative 5x5 matrix, is there a quick way to automate the simulation of all the antidiagonals?</p><pre class="language-matlab">a(1,1) =1
a(2,1) =2
a(1,2) =2
a(3,1)= 3
a(2,2)=3
a(1,3)=3
a(4,1)=4
a(2,3)=4
a(3,2)=4
a(1,4)=4
a(1,5)=5
a(4,2)=5
a(3,3)=5
a(2,4)=5
a(5,1)=5
a(5,5)=1
</pre>GEORGIOS BEKAShttps://nl.mathworks.com/matlabcentral/profile/authors/11075599-georgios-bekastag:nl.mathworks.com,2005:Question/3831962018-02-17T05:21:42Z2018-02-17T20:54:49ZGenerating uniformly distributed points in a spherical volume<p>Is there any method to generate uniformly distributed points(3D coordinates) in a spherical volume?</p><p>Thanks</p>shyam kumar mhttps://nl.mathworks.com/matlabcentral/profile/authors/4780326-shyam-kumar-mtag:nl.mathworks.com,2005:Question/3832502018-02-17T16:01:38Z2018-02-17T20:51:12ZEfficient way of storing a triangular matrix<p>Hi all,</p><p>I have some pretty large upper triangular matrices to store and to be used like this:</p><img src = "/matlabcentral/answers/uploaded_files/105172/tritotri.png"><p>As you see, these matrices are full in upper triangle and zeros in lower triangle. However, Matlab is not optimised to store such matrices, using sparse only makes the memory cost slightly larger.</p><p>So shall I vectorise these matrices to vectors, such that Matlab only stores the real numbers, and then after the operations I change them back to upper triangular matrices? If I should, is there any efficient functions to achieve this?</p><p>Many thanks!</p>Xiaohan Duhttps://nl.mathworks.com/matlabcentral/profile/authors/7807151-xiaohan-dutag:nl.mathworks.com,2005:Question/3832812018-02-17T20:17:09Z2018-02-17T20:39:39ZWhy is the Antenna Designer app return 'Undefined function or variable'?<p>Clicking on the Antenna Designer icon in the apps dropdown returns</p><pre class="language-matlab">Undefined function or variable 'antennaDesigner'.
</pre><p>Running restoredefaultpath and pathtool does nothing. Running 2017a.</p>Joseph Stavitskyhttps://nl.mathworks.com/matlabcentral/profile/authors/12182772-joseph-stavitskytag:nl.mathworks.com,2005:Question/3832792018-02-17T20:07:37Z2018-02-17T20:38:42Zjacobi method using one for loop<p>I have a code written that will use jacobi method to solve a problem but in my numerical methods class I need to be able to perfrom this function in one loop. Here is my current code:</p><pre class="language-matlab">if true
% code
function X=jacobi(A,B,P,delta,max1)
N = length(B);
for k=1:max1
for j=1:N
X(j)=(B(j)-A(j,[1:j-1,j+1:N])*P([1:j-1,j+1:N]))/A(j,j);
end
err=abs(norm(X'-P));
relerr=err/(norm(X)+eps);
P=X';
if (err<delta)||(relerr<delta)
break
end
end
X=X';
end
end
</pre><p>And this seems to work. It defines X(j) and spits out values from 1 to the length of B(100). Now I need to find a way to make this run using only ONE for loop. so I need to probably get rid of the j indices and replace it with k. Anyone know how I can make this work?</p>Isaac Al-raihttps://nl.mathworks.com/matlabcentral/profile/authors/6207538-isaac-al-raitag:nl.mathworks.com,2005:Question/3823652018-02-13T09:57:33Z2018-02-17T20:29:49Zbounjours a tous , alors j'ai commence de trvaille avec matlab j'ai esseye de faire le produit de convolusion entre une image et un filtre gaussian avec la fonction conv2 mais je suis bloqué a cause de ca voila l'erreur:N-D arrays are not supported.<pre class="language-matlab">sigma1 = 1.9;
sigma2 =2.8;
img=imread('image.jpg');
hsize = [3,3];
h1 = fspecial('gaussian', hsize, sigma1);
h2 = fspecial('gaussian', hsize, sigma2);
% [a,b]=size(img);
% m1=max([a+3-1,a,3]);
% n1=max([b+3-1,b]);
% im1=cell(m1,n1);
im1=conv2(img,h1);
im2=conv2(img,h2);
</pre>amal abbbeshttps://nl.mathworks.com/matlabcentral/profile/authors/12153162-amal-abbbestag:nl.mathworks.com,2005:Question/3832622018-02-17T17:58:04Z2018-02-17T20:17:13ZOpen a series of images and save them in another folder<p>Hi,I want to open images from one folder and save the 8-bit images in another existed folder using original name. Here is my code:</p><p>close all;
rand('seed',0);</p><p>folder = 'F:'
files = [folder filesep '\*.tif']</p><p>files = dir(files);
n = numel(files)</p><p>for k=1:n</p><pre> fullFileName = fullfile(folder, files(k).name);
idx=randi(k);
im = files(idx).name;
afm = imread(fullfile(folder,im));</pre><p>I8bit =im2uint8(afm);</p><p>[pathstr,name,ext] = fileparts(fullFileName) ;
filename = strcat(pathstr,name,'.tif');</p><p>my_file = "F:\8bit\filename";</p><pre> imwrite(I8bit,filename)
end</pre><p>But the images were not able to be saved in that folder, can anyone help me? Another question is my code can only open jpg files if I change hat to '*\.jpg', with tif (as shown above) not able to open. Can anyone give me a hand? Thank you so much in advance.</p>Tian Tianhttps://nl.mathworks.com/matlabcentral/profile/authors/10670225-tian-tiantag:nl.mathworks.com,2005:Question/3832752018-02-17T19:21:57Z2018-02-17T20:07:29ZHow can I write a condition statement in for loop?<p>I have this code. I want if the a=>6 the code increase k by one and go back from the beginning of the for loop. how can I do it ?</p><pre> k=4;
b=[2,5,2,6,3,4,5,9,10,2,9,4,6,8,7,3,4];
c=[5,2,5,6,9,8,3,1,6,5,5,3,6,4,1,6,9];
for i=1:k
a=b(1,i)+c(1,i);
ss(1,i)=a;
if a>6 then % this does not work </pre><pre> k=k+1
end
end
ss</pre><p>The code I wrote does not work. How can I write this condition ?</p>zeezohttps://nl.mathworks.com/matlabcentral/profile/authors/8148537-zeezotag:nl.mathworks.com,2005:Question/2669692016-02-07T08:21:07Z2018-02-17T20:06:11ZCombine two matrices (every other column)<p>I have two matrices A and B which are for example</p><p>A=[1 2 3;4 5 6; 7 8 9] and B=[10 11 12; 13 14 15; 16 17 18]</p><p>And I would like to combine these matrices so that every other column is from A and every other is from B. So the answer should be matrix:</p><p>[1 10 2 11 3 12; 4 13 5 14 6 15; 7 16 8 17 9 18]</p><p>Of course my matrices are not only 3x3 matrices but n x n matrices.</p><p>My history with Matlab is so short that I don't figure out if that is even possible to do?</p>Snowfallhttps://nl.mathworks.com/matlabcentral/profile/authors/7587828-snowfalltag:nl.mathworks.com,2005:Question/3826742018-02-14T14:44:58Z2018-02-17T19:59:53ZApplication of Particle Swarm Optimization to solve linear system of equations<p>Hi, I have a linear system of equations in the matrix notation form Ax=b, with A is 27*27, b vector is 27*1, and we want to solve for x which is vector of 27 unknowns (i.e, 27*1).
Any help to use PSO to solve like this system due to the condition number is high so solving using x=inv(A)*b is a bad solution.</p>M.Shaarawyhttps://nl.mathworks.com/matlabcentral/profile/authors/11317174-m-shaarawytag:nl.mathworks.com,2005:Question/3832512018-02-17T16:12:33Z2018-02-17T19:57:05ZHow to find centroid of experimental data ?<p>I am using MATLAB to calculate the centroid of data which i am importing from Excel spreadsheet. However, I have to use integration to calculate centroid. I am using trapz function to calculate integration.The formula which i am using here to integrate is mentioned in image.To implement (x*dx), i am using (1/2)*(d(x^2)).</p><img src = "/matlabcentral/answers/uploaded_files/105174/centroid.png"><p>But results are not up to mark.I am mentioning the code which i am using.</p><pre> format longG;
filename='xyz.csv';
sheet=1;
col1=1; %Starting Column; Nx(charge) density Values %
col2=(col1)+1; %X values % </pre><pre> row1=10; %Starting Row Number%
row2=20; %Ending Row Number%</pre><pre> Data=csvread(filename); % Data File Reading%</pre><pre> % Access of Columns for Charge Density & X %
charge_density=(Data(row1:row2,col1))'; %Charge density Data in row matrix%
x=(Data(row1:row2,col2))'; </pre><pre> max_charge_density=max(charge_density(:)); %maximum value of charge density%
normalized_charge_density=(charge_density./max_charge_density);</pre><pre> %%%%%%%%%%%%%%%%%%%%%For Double Gate FET %%%%%%%%%%%%%%%%%%%</pre><pre> Tfin=2; %Thickness of fin %
normalized_x=x/Tfin; %Normalized Distance%
x_square=normalized_x.^2; %square of normalized distance x%</pre><pre> %%% Integration of charge density with respect to Distance%%%
numerator=(trapz(x_square,normalized_charge_density))*(1/2);
denominator=trapz(normalized_x,normalized_charge_density);</pre><pre> %Centriod Calculation%
centroid= (numerator/denominator);</pre>Amratansh Guptahttps://nl.mathworks.com/matlabcentral/profile/authors/12181751-amratansh-guptatag:nl.mathworks.com,2005:Question/3832702018-02-17T18:42:35Z2018-02-17T19:53:41ZControl colorbar in a plot<p>Dear all,
I was wondering if anyone knows a way of controlling the colorbar of a plot?
At the moment I have the following code:
subplot(3,1,3);
[cs2,h2]=contourf(xgrid,ygrid,U_40cm,10); hold on;
clabel(cs2,h2);
h2.LevelList = round(h2.LevelList, 2);
set(gca, 'CLim', [-25 20]);
xlabel('$y$ $(cm)$','interpreter','latex','Fontsize',14,'Fontname','Times'),
ylabel('$z$ $(cm)$','interpreter','latex','Fontsize',14,'Fontname','Times'),
%set(gca,'xtick',83:1:92,'Fontsize',16,'Fontname','Times'),
%set(gca,'ytick',1:0.5:4,'Fontsize',16,'Fontname','Times'),
axis([83 92 1.2 3.9]);
colormap('jet')</p><p>In the colorbar, matlab is just presenting the values -20,0,20. Is there any way of forcing matlab to present instead -20,-10,0,10,20? I need this to make the appearance of this plot compatible with other plot.
Thanks in advance.</p>antonio ferreirahttps://nl.mathworks.com/matlabcentral/profile/authors/2209644-antonio-ferreiratag:nl.mathworks.com,2005:Question/3742012017-12-22T11:23:13Z2018-02-17T19:47:21ZHow to model a state space model of Induction Motor considering Iron loss?<p>To study the characteristics of IM with and without considering Iron Loss.</p>saurabh nandyhttps://nl.mathworks.com/matlabcentral/profile/authors/4007401-saurabh-nandytag:nl.mathworks.com,2005:Question/3802482018-02-01T18:57:19Z2018-02-17T19:46:22ZCSI inverter simulink model<p>Please help me with the simulink model of CSI(3 phase)Inverter model that can be used with the Induction motor control(IFOC) for induction motor drives</p>Aliprio Hazrahttps://nl.mathworks.com/matlabcentral/profile/authors/11269322-aliprio-hazratag:nl.mathworks.com,2005:Question/3832712018-02-17T19:00:47Z2018-02-17T19:39:33Zwanted help in matlab code<p>I have:</p><pre> d1=k(1); d2=k(2);d3=k(3)...............d190=k(190);</pre><p>then</p><pre> p1=k(191);p2=k(192);p3=k(193)..................p220=k(310)</pre><p>To avoid writing all the terms individually, i want to define these statement in short,
something like</p><pre class="language-matlab">d(1:190)=k(1:190);
</pre><p>and then</p><pre> p(1:22)=k(191:310)</pre><p>Is this way of writing correct.</p><p>Thanks in advance</p>adarshhttps://nl.mathworks.com/matlabcentral/profile/authors/2935741-adarshtag:nl.mathworks.com,2005:Question/3831382018-02-16T17:55:27Z2018-02-17T19:37:00ZHow can I save ALL workspace variables?<p>Hello! I have 7104 .mat files, each of them has different variables inside. I was asked to transfer these matlab files to .cdf or .txt files. Is it possible to do it automatically? My best guess is to open all of them one by one in a loop and save the variables into new files. But how can I save ALL workspace variables? They all have different names from file to file...</p>Artem Smirnovhttps://nl.mathworks.com/matlabcentral/profile/authors/8719728-artem-smirnovtag:nl.mathworks.com,2005:Question/3832732018-02-17T19:12:12Z2018-02-17T19:33:31Zwriting lower and upper bound in genetic algorithm<p>I have 200 number of variables, each having lower and upper bound
first 50 variables are for pressure (all having lower and upper bound as 10 and 20 respectively), second 50 are for diameter(all having lower and upper bound as 16 and 30 respectively), next 50 are for flow rate (all having lower and upper bound as 15 and 20 respectively) and finally next 50 are velocity( all having lower and upper bound as 6 and 20 respectively). How to write in Genetic algorithm.</p><pre class="language-matlab">xl=[10 10 10 10 .......10 16........16...........15.....6................]
xu=[20.................20 30 30...........20.....20...............]
</pre><p>is there any way in programming , through which i can state that variables 1 to 50 have lower and upper bound as 10 and 20, and in the same way for all.</p>adarshhttps://nl.mathworks.com/matlabcentral/profile/authors/2935741-adarshtag:nl.mathworks.com,2005:Question/3832762018-02-17T19:25:28Z2018-02-17T19:25:28ZHow can I change the text color Matlab Publishing Markup?<p>I am using publish to generate PDF reports through Matlab. I am wondring if there is anyway to control the color of the published text; it is always black. Your input is highly appreciated.</p>Fahad Alsulaimanhttps://nl.mathworks.com/matlabcentral/profile/authors/11866579-fahad-alsulaiman