https://fr.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-12-13T22:18:22Ztag:fr.mathworks.com,2005:Question/3728302017-12-13T21:56:27Z2017-12-13T22:18:22ZHow to sort the matrix rows based on a function over the rows<p>Let's say I have a <b>Nx3</b> matrix <b>M</b> of <i>double</i>.</p><p>Consider, for example, a function <b>Map(a,b,c)</b> that returns a <i>double</i></p><p>How can I sort <b>M</b> so that the rows with smallest <b>Map</b> come first?</p><p>For example, the first row should be <b>i</b> if <b>Map(M(i,1), M(i,2), M(i,3))</b> value is the smallest between <b>Map(M(j,1), M(j,2), M(j,3))</b> for any <b>1 ≤ j ≤ N</b> and <b>j ≠ i</b></p>Daniel Texhttps://fr.mathworks.com/matlabcentral/profile/authors/11715856-daniel-textag:fr.mathworks.com,2005:Question/3604372017-10-09T15:38:55Z2017-12-13T22:16:26ZAvoid "unnecessary data type conversion" warnings without switching of the respective diagnostics<p>I have a low pass filter library block using the "Conversion Inherited" block
to maintain fixed point scaling. In some cases the fixed point scaling of the incoming signal
has no fraction (2^0 scaling) and so should be the output.
Here the "Conversion Inherited" naturally has no effect and I get "Unnecessary type conversions"
warnings. But even if it wasn't inside a library, that is used in many other places, I would
like to keep the conversion block as it should grant me the right data type of the output with
respect to the input signal, which IMHO is exactly what the "Conversion Inherited" block is made for.
Is there any workaround allowing me to keep the diagnostics as well as the "Conversion Inherited"
block without the wrong diagnostics with it?</p><p>TIA, Robert</p>Roberthttps://fr.mathworks.com/matlabcentral/profile/authors/84560-roberttag:fr.mathworks.com,2005:Question/3728292017-12-13T21:55:23Z2017-12-13T22:12:54ZCreating a cell array dynamically & manipulating matrices inside the cell array<p>Hi,</p><p>I am trying to create a cell array dynamically.</p><p>I am reading several matrices off of an excel file.
For example: If I read 4 matrices: A,B,C,D.</p><p>I will create cell array E={A,B,C,D} but, I want the code to create this cell array dynamically depending on how many excel files (or sheets) I read.</p><p>Basically, it should be able to figure out the number of matrices and assign it variables in the cell array without me having to tell it how many matrices I have read from the excel sheet.</p><p>For example: If I read 8 excel sheets I should get 8 matrices in the cell array & If I read 12 matrices I should get 12 matrices in the cell array,etc. dynamically.</p><p>I am also wondering about how to manipulate each matrix inside the cell array like I normally would do without the cell array.</p><p>I know how to select a specific matrix inside the cell array but, I don't know how to manipulate a specific matrix inside the cell array & store it somewhere else. Can this be only done with the help of a 3D matrix or is there another way?</p><p>There is a reason I am using the cell array so, I don't think that I will change that part but, maybe If I can do the same thing dynamically using a 3D matrix instead of a cell array in an easier way I can accept that too.</p><p>The reason is I am using a <b>for loop</b> which does the same calculation over and over again but, changes the matrix inside the calculation & I am supposed to manipulate the elements inside each matrix & use multiple matrices at the same time for the calculation (to be specific 2 matrices at the same time & manipulate these matrices).</p><p>I can write the code the normal way & it will do the job but, the number of lines would be a lot to do the same exact thing.</p><p>I am not sure if this is detailed enough so, if you need more details I can show you why I am trying to use a cell array but, I just felt like it will be a longer explanation & that's why I tried to cut it short here.</p><p>Any help is appreciated. Thank you in advance.</p>Yildirim Kocogluhttps://fr.mathworks.com/matlabcentral/profile/authors/4589821-yildirim-kocoglutag:fr.mathworks.com,2005:Question/326172012-03-18T12:56:57Z2017-12-13T22:05:19ZHow to remove ticks from the x-axis?<p>Hi everybody,</p><p>I am wondering if there is any way to remove the ticks from <b>only one axis</b>, let say x-axis, when you plot a graph. (TickLength applies the changes to both x- and y-axis which is not what I'd like)</p><p>Thank you very much in advance,
Vahid</p>Vahidhttps://fr.mathworks.com/matlabcentral/profile/authors/3137849-vahidtag:fr.mathworks.com,2005:Question/3728312017-12-13T22:02:48Z2017-12-13T22:02:48ZDisplay texture image based on GLCM matrix<p>Hi,
I used graycomatrix and graycoprops functions in order to get texture features of an input image.
Now , i want to display separately each texture image (Contrast Image, Entropy image, etc.) but i dont know how to deal with it. Could any one help please ?</p>Ineshttps://fr.mathworks.com/matlabcentral/profile/authors/2961706-inestag:fr.mathworks.com,2005:Question/3728062017-12-13T19:01:30Z2017-12-13T21:59:10Zhow to use sprintf with fullfile<p>I have the following code:</p><pre class="language-matlab">myFolder = 'D:\data';
myFiles = fullfile(myFolder,'*.txt');
allFiles = dir(myFiles);
</pre><pre class="language-matlab">for i = 1 : length(allFiles)
baseFilename = allFiles(i).name;
Filename = fullfile(myFolder,baseFilename,sprintf('%d%02d.txt',i));
fid = fopen(Filename);
A{i} = fscanf(fid, '%d %d %d');
fclose(fid);
end
</pre><p>I got an error 'invalid file identifier'. My Filename is incorrect. How should i write sprintf together with fullfile. My file names written as 0101,0102,...,6001,6002.txt.</p>milly edroshttps://fr.mathworks.com/matlabcentral/profile/authors/11744696-milly-edrostag:fr.mathworks.com,2005:Question/3728042017-12-13T18:45:44Z2017-12-13T21:49:23Zfor loop ode 45 changing parameter values<p>I'm trying to run this code and use only the last value of the tspan for the ode45, however I always get 2 values for the final value of the tspan (when t=100)</p><p>This is the code:</p><pre class="language-matlab">ABP=linspace(40,170,131);
ti=0; tf=100;
%change in ABP at every loop
</pre><pre> for i=1:1:length(ABP)
sol = ode45(@first,ti:1:tf, [0 0 0 0 0.205 62.516 12 13.201 0.2 1],[],ABP(i)); %(function, timespan, initial condition for xq,xc,xm1,xm,Ca,P1,V_sa,P2)
end</pre><pre class="language-matlab">%% ========= FUNCTION ==================
function dvdt = first(t,v,ABP)
%code
...ABP used in a set of differential eq...
if t==100
van= (Vsa+Vla)/(Vsab+Vla)
fileID=fopen('van.txt','a');
fprintf(fileID,' %4.3f\n',van);
fclose(fileID);
</pre><pre> end
end</pre><p>Hence, I should end up having a .txt file with 131 values of <b>van</b>, one for each value of <b>ABP</b>. Instead, I end up with double the amount. I also printed the <b>ABP</b> values in the txt file to check, and indeed there were two different (very similar) values of <b>van</b> for each value of <b>ABP</b>.
Any suggestions on how to fix this?</p>gorilla3https://fr.mathworks.com/matlabcentral/profile/authors/8874269-gorilla3tag:fr.mathworks.com,2005:Question/3715152017-12-06T21:09:29Z2017-12-13T21:48:46ZHow do I plot convergence in Newton's method to find square root?<p>I have the following function to find the square root of a number a, in this case it is 2:</p><pre class="language-matlab">function [sqrta,n] = newton()
a = 2;
tol = 1e-10;
n = 0;
sqrta = a;
sqrtaminus1 = a;
while abs(sqrta^2 - a) > tol
sqrta = 0.5*(sqrtaminus1 + (a/sqrtaminus1));
n = n + 1;
sqrtaminus1 = sqrta;
plot(sqrta,n);
end
</pre><p>I run this by:</p><pre class="language-matlab">>> [sqrta,n] = newton()
</pre><p>I'm making some mistake while plotting for convergence. I know I am making a fatal error without understanding the concept of convergence. It'd be great if someone could help me. Thanks!</p>Sreenath Umagandhihttps://fr.mathworks.com/matlabcentral/profile/authors/9549365-sreenath-umagandhitag:fr.mathworks.com,2005:Question/3719912017-12-09T03:53:05Z2017-12-13T21:52:20ZError using symengine Unable to define a matrix over 'Dom::ExpressionField()'.<p>Hi, i'm trying to solve an unknown number of nonlinear ode using central difference approximation and newtons method.</p><p>I can't seem to figure out why i would have used .' syntax when i made my newtons method code and i think that it might be causing the error? I'm not exactly sure... This is for a numerical methods class as a chemical engineer undergrad, so my knowledge of cs is limited.</p><pre class="language-matlab">function [ guesses ] = newtons_method( A,b,guesses,convergence)
%newtons method using jacobian
%will err if divide by 0 from initial guess
%avoiding using jacobian() because its inbuilt function
%inv_jaco = inv(self_jacobian(A,b));
inv_jaco = inv(jacobian(A,b));
x0 = sym('A', [1 size(A,1)]); %will contain equation values
guesses=double(guesses);
x_history=[]; %record to calculate convergence speed
error = 1;
while error > convergence
for j=1:size(b,2)
x0(j) = subs(A(j),b,guesses); %equation values
end
x_history = guesses;
subs_jaco=subs(inv_jaco,b,guesses);
guesses = guesses.' - (subs_jaco * x0.'); % .' playing with matrix dimensions
guesses=guesses.';%******
error=abs(guesses(2) - x_history)/guesses(2);
end
guesses=double(guesses);
end
</pre><p>and the code i'm trying to run:</p><pre> clear all; clc; close all</pre><pre> n=5;
y = sym('y', [1 n+2])
yb = sym('yb', [1 n+2]) %unknown number of variables if n changes</pre><pre> A = sym('A', [2 n+2]) %2*
guesses=linspace(0.1,1,2*n+4)%+4
dx=1/(n-1);
x=[];
for i=1:n
x=[x i/n]
end</pre><pre> A(1)=(y(3)-y(1))/(2*dx)-y(2)+1;
A(n+2)=(y(n)-y(n-2))/(2*dx)+.1*y(n-1);
%
A(n+3)=(y(3)-yb(1))/(2*dx)-yb(2)+1.5;
A(2*n+4)=(yb(n)-yb(n-2))/(2*dx)+.05*yb(n-1);
%
for i=2:n+1
A(1,i) = .01*(y(i+1) - 2*y(i) + y(i-1))/dx^2 - yb(i)*y(i)^2 - .02*y(i); %ybi
end
for i=2:n+1
A(2,i) = .01*(yb(i+1) - 2*yb(i) + yb(i-1))/dx^2 - y(i)*yb(i)^2 - .05*yb(i); %ybi
end
var=[y yb] %in order to make it a single vector</pre><pre> A=[A(1,1:end) A(2,1:end)]; %single vector</pre><pre> ys = newtons_method(A,var,guesses,.99) %A matrix, variables, initial values, tolerance</pre><p>Thanks for any help and/or pointers!</p>Nathan D'Souzahttps://fr.mathworks.com/matlabcentral/profile/authors/6881647-nathan-d-souzatag:fr.mathworks.com,2005:Question/3728282017-12-13T21:46:53Z2017-12-13T21:46:53ZHow I clear the memory of a GUI without closing the windows?<p>I'm doing a CNC simulator with GUIDE, but after running the simulation, the program remains with a high consumption of RAM,
only when it closes and reopens the memory starts to go down again</p>bayran arrietahttps://fr.mathworks.com/matlabcentral/profile/authors/8034309-bayran-arrietatag:fr.mathworks.com,2005:Question/3727862017-12-13T16:51:18Z2017-12-13T21:45:37ZMaking a three column matrix<p>Hi everyone!
I am having trouble with the following:
I have built a 31 row by 3 columns ceros matrix and I am trying to index values to each column, I want my first column to go from 140 to 440(this are lengths), but when trying to do so my values start from 0, then 140, then 440...
Then in the second column I want the values of column 1 to appear because I need to compare how many lengths are being acumulated( this to later build a histogram..)
I would very much appreciate your help!</p>Liliana Sierrahttps://fr.mathworks.com/matlabcentral/profile/authors/11262420-liliana-sierratag:fr.mathworks.com,2005:Question/1713212015-01-23T14:36:01Z2017-12-13T21:37:24ZMatlab Screen Size incorrect<p>Seems as if with matlab 2014b the screen size query is off. Have a look at the attached screenshot. Obviously they disagree. Has anyone seen this before?</p><p>Trevor</p>Trevor Harrishttps://fr.mathworks.com/matlabcentral/profile/authors/3447833-trevor-harristag:fr.mathworks.com,2005:Question/3722512017-12-11T09:57:23Z2017-12-13T21:34:51ZHow to read a gzip compressed file without unzipping it to the harddrive?<p>I have thousands of small (100kb) .gz (gzip-compressed) files. The goal is to read the data and store it in a workspace variable. Until now I haven't found a way around unzipping the files to the harddrive and subsequently opening the new 5 times larger file, reading and deleting it again. Unzipping is done by the gunzip-function.
This process is very time consuming and not possible when dealing with 30000 files.</p><p>Do you have a recommendation for me how to accelerate the process of reading my files? Thanks!</p>Felix Willemshttps://fr.mathworks.com/matlabcentral/profile/authors/10625204-felix-willemstag:fr.mathworks.com,2005:Question/3728222017-12-13T20:24:54Z2017-12-13T21:32:45ZHow to change the year format in time series data? ("0017" to "2017")<p>Hi. I need help. I want to ask about how to change the format of year in Matlab. I intend to concatenate horizontally two data based on the datetime data. Both data has the same range of datetime. However, turns out one data has this format for the year "0017' and the other is "2017", so that they can not concatenate. I want to ask about how to change 0017 to 2017, but not limited to 2017. For example if the data is based on 2018 time series data. One data would be 0018 and the other is 2018. I attach the two tables here. One with 0017 and the other with 2017. Once I change 0017 to 2017, they both can concatenate horizontally.</p><pre class="language-matlab">20.Nov.0017 00:00:00
20.Nov.0017 00:05:00
20.Nov.0017 00:10:00
20.Nov.0017 00:15:00
20.Nov.0017 00:20:00
20.Nov.0017 00:25:00
</pre><p>and the other data :</p><pre> 20.11.2017 00:00:00
20.11.2017 00:05:00
20.11.2017 00:10:00
20.11.2017 00:15:00
20.11.2017 00:20:00
20.11.2017 00:25:00
20.11.2017 00:30:00</pre><p>Could you please help me? I am really stuck in this thing. Thank you very much for your help.</p>Kasih Ditaningtyas Sari Pratiwihttps://fr.mathworks.com/matlabcentral/profile/authors/9154438-kasih-ditaningtyas-sari-pratiwitag:fr.mathworks.com,2005:Question/3728272017-12-13T21:06:46Z2017-12-13T21:30:01Zfsolve multi variables help<p>I am trying to solve for angles in a system given 2 equations and 2 unknowns. First I defined ,y two functions in the form</p><p>function F=myfun(theta2, theta3, theta4)
F=[.2+.05.*cos(theta2)+.304.*cos(theta3)-.2.*cos(theta4);
.1+.05.*sin(theta2)+.304.*sin(theta3)-.2.*sin(theta4)];
end</p><p>then I attempt to solve for the unknowns using fsolve</p><p>theta3(1)=170.69;
theta4(1)=116.56;
x0=0
for theta2=-90:5:270;
options = optimset('Display','iter');
x=fsolve(@myfun,X0,options);
end</p><p>what am I doing wrong? is this even possible?</p>Emilio Lopezhttps://fr.mathworks.com/matlabcentral/profile/authors/7013067-emilio-lopeztag:fr.mathworks.com,2005:Question/3726852017-12-13T08:26:07Z2017-12-13T21:15:25ZLocation pixel and slice<p>Hi everyone.</p><p>Please help me. Now i have 20 slice image PET(dicom format dimension 256x256). How to determine:</p><p>1) The extrat location of pixel value with range 10000-32000 every slice.</p><p>Example: [rows, column, PixelValue]=</p><p>Below is my code to read all the 20 slice:</p><p>first_to_read = 1;
last_to_read = 20;
num_to_read = last_to_read - first_to_read + 1;
for file_idx = 1 : num_to_read
img_number = file_idx + first_to_read - 1;
filename = fullfile('D:\Images PET and CT\PET', sprintf('PET_I1001_PT%03d.dcm', img_number));
X(:, : , 1, file_idx) = dicomread(filename);
end</p><p>Help me..</p>mohd akmal masudhttps://fr.mathworks.com/matlabcentral/profile/authors/10957567-mohd-akmal-masudtag:fr.mathworks.com,2005:Question/3726992017-12-13T10:09:33Z2017-12-13T21:09:00ZThis code only plot for last value of r1, how to plot for all values of r1<pre class="language-matlab">clc
clear
format longg
for r1 = 0:.1:1;
r2 = 1-r1;
f1 = 0:0.1:1;
f2 = 1-f1;
F1 = ((r1.*f1.^2)+(f1.*f2))./((r1.*f1.^2)+(2*f1.*f2)+(r2.*f2.^2));
end
plot(f1,F1,'-o')
</pre>Taha Abbas Bin Rashidhttps://fr.mathworks.com/matlabcentral/profile/authors/7949631-taha-abbas-bin-rashidtag:fr.mathworks.com,2005:Question/3728192017-12-13T20:14:36Z2017-12-13T21:05:28ZFunctions reuse in generated code<p>I have a Simulink 2014a model that contains two identical subsystems from a user-defined library. For these subsystems, function packaging parameter is set to reusable. One of the subsystems inputs are fed by constant block, while the other subsystem inputs are fed by gain blocks.
In the generated code (using embedded coder), the functions generated for the two subsystems aren't being reused. When comparing subsystem checksum, I noticed that "ReadsInputInStartFcn" identifier is different between the two subsystems. Note that, I am using a "MATLAB Function (fcn)" block in both subsystems.
Could you please explain the root cause of this difference?</p>Amr Nagatyhttps://fr.mathworks.com/matlabcentral/profile/authors/10262667-amr-nagatytag:fr.mathworks.com,2005:Question/3728252017-12-13T20:56:57Z2017-12-13T20:56:57ZHow to manage with neural net errors ?<p>Suppose you train a neural net for classification.
When testing, we get an accuracy of 95%</p><p>This means that when using this classifier, we have 5% risk of misclassification
So, how to trust the obtained result and how to deal with this risk ?
With other words : how do professionnal applications solve this issue ?</p><p>Ex : I detect that traffic light is green (95%) but may also be red (5%). How do I choose what to do : go on or stop ?</p><p>I'm looking for documents about this subject</p>Herve POSTEChttps://fr.mathworks.com/matlabcentral/profile/authors/6229126-herve-postectag:fr.mathworks.com,2005:Question/3728122017-12-13T19:42:37Z2017-12-13T20:56:06ZWhat does this BODE plot from SIMULINK tell me? - Please see attachment<p>I have attached my BODE plot and I need some help in understanding what it actually means.</p>hoomsn samivandhttps://fr.mathworks.com/matlabcentral/profile/authors/9634794-hoomsn-samivandtag:fr.mathworks.com,2005:Question/3723612017-12-11T18:36:15Z2017-12-13T20:54:41ZIs it possible to Create Custom Arduino Add-On Device, Library, or Code for Arduino DUE?<p>I wrote a custom Arduino Add-On following documentation (Create Custom Arduino Add-On Device, Library, or Code) that works very well on Arduino UNO and MEGA.
When I update my Add-On on Arduino DUE using the following command:</p><pre class="language-matlab">a = arduino('COM10', 'due', 'Libraries', 'ExampleAddon/HX711');
</pre><p>an error occurs: <b>Cannot program board Due (COM10). Please make sure the board is supported and the port and board type are correct. For
more information, see Arduino Hardware Troubleshooting.</b></p><p>The arduino board is original and works well when using Matlab Support package and libraries such as SPI or I2C.
If I upload the Arduino server with "arduinosetup" command, no errors occur and my library is detected by "listArduinoLibraries", but when I create an arduino object, Matlab starts uploading server again without my library.
I thought there's some special code that must be included in C++ header file, but I can't find anything in documentation. In Matlab support package description this functionality seems to be supported.</p>NICHOLAS GIACOBONIhttps://fr.mathworks.com/matlabcentral/profile/authors/7779346-nicholas-giacobonitag:fr.mathworks.com,2005:Question/3728242017-12-13T20:47:45Z2017-12-13T20:48:32ZHow can i generate a .wav file consist of a pure tone that has f=1000 Hz, with an ascending loudness(volume) from 0dB to 80dB ,with time duration of 15 second.and the same with other frequency f=4000Hz<p>Iam not profisssional in matlab.</p><p>maybe like this
freq = 4000;
w = sin(linspace(0, 2000*pi, freq * 15));
sound(w, freq); % full volume</p><p>iniVolume = 0;
finVolume = 80;
Volume = linspace(iniVolume, finVolume, length(w));
w2 = w .* Volume;
sound(w2, freq);
%wavwrite(x,Fs,16,'test.wav');</p>Moe Alhasanhttps://fr.mathworks.com/matlabcentral/profile/authors/11745423-moe-alhasantag:fr.mathworks.com,2005:Question/3728012017-12-13T18:31:13Z2017-12-13T20:44:53ZMultiple input delay block (simulink)<p>I need more inputs for delay block, how should i do?</p>Damiano Capoccihttps://fr.mathworks.com/matlabcentral/profile/authors/10003105-damiano-capoccitag:fr.mathworks.com,2005:Question/239352011-12-14T14:27:15Z2017-12-13T20:41:58Zhow to count row and column of a matrix<p>if i have a big matrix and i don't know its size, how to find out its size? and how to save it as variable?</p>erihttps://fr.mathworks.com/matlabcentral/profile/authors/94617-eritag:fr.mathworks.com,2005:Question/2826882016-05-05T10:44:48Z2017-12-13T20:41:32Zwhy my excel file can not be read by matlab?<p>I have simple excel file including date and rainfall in two columns.
the matlab can not read the file, either import data by xlsread command.
I made two format .xls and .xlsx. but matlab has an error.
just it can read .csv file.
matlab version is 2016a.
error message after command
Error using xlsread (line 251)
Error: The server threw an exception.</p>Miladhttps://fr.mathworks.com/matlabcentral/profile/authors/8000073-miladtag:fr.mathworks.com,2005:Question/3728202017-12-13T20:19:52Z2017-12-13T20:40:46ZExtracting sum of intensity values at various locations with various diameters<p>Hello.
I have an image (grayscale) of spots, that have a spread of intensities and sizes.</p><img src = "/matlabcentral/answers/uploaded_files/98466/im113.png"><p>I have the centroid location of each spot and an "size" of each spot obtained by my own encircled energy calculation for both x&y directions.</p><pre class="language-matlab">data =
</pre><pre> 8.35 8.14 43.00 2266.00
10.76 8.24 43.00 2362.00
8.96 11.07 43.00 2459.00
8.55 7.98 43.00 2555.00</pre><p>where</p><pre class="language-matlab">col 1 is the size of my object in y
col 2 is the size in x
col 3 is the x centroid location
col 4 is the y centroid location
</pre><p>What I am trying to achieve is at each x,y centroid location, draw a circle with a diameter given by the average of the size in x & size in y, and then caluclate the integrated intensity in the circle. The circles (representing the size) may be different for each spot.</p><p>As a second request,
I would also like to then consider a distance d, say 15 pixels from the x,y centroid location and obtain the background values from a square or circle that I can call background to then subtract from the integrated signal requested above to get the background subtracted integrated signal.</p><p>Thanks for any help
Jason</p>Jasonhttps://fr.mathworks.com/matlabcentral/profile/authors/1217570-jasontag:fr.mathworks.com,2005:Question/3728082017-12-13T19:04:01Z2017-12-13T20:40:02ZHow can I plot slope including maximum peaks?<img src = "/matlabcentral/answers/uploaded_files/98456/hshshshsh.png"><p>Hello,
How can I plot slope including peaks point? It should look like exp. I tried envelope but It does not work for my code.</p><p>Thank you.</p>Ezgi Ertunçhttps://fr.mathworks.com/matlabcentral/profile/authors/6240805-ezgi-ertunctag:fr.mathworks.com,2005:Question/3727872017-12-13T16:52:28Z2017-12-13T20:36:04ZAssigning multiple variables vectors from a cell array<p>I'm wondering if there is any smart solution on how to access multiple same-sized vectors inside of a cell array and assign them to an independent variable.</p><pre class="language-matlab">cellArray =
</pre><pre> 1×4 cell array</pre><pre> {1×101 double} {1×101 double} {1×101 double} {1×101 double}</pre><p>Thanks!</p>Johannes Bergerhttps://fr.mathworks.com/matlabcentral/profile/authors/9534938-johannes-bergertag:fr.mathworks.com,2005:Question/3363862017-04-20T20:22:22Z2017-12-13T20:31:19ZHow can I change the IP address of my Zynq Board (ZC706), other than the default '192.168.4.2' ? I'm using R2016a.<p>It seems that with R2017a, it is possible to change the Zynq board communication address using the visionzynq command:</p><p>vz = visionzynq(DeviceName,DeviceAddress) creates a visionzynq object connected to the DeviceName type of Zynq board, with a custom IP address, DeviceAddress.</p><p>My problem is with R2016a, the DeviceAddress parameter is not supported with the visionzynq command.</p>fenderfredhttps://fr.mathworks.com/matlabcentral/profile/authors/4272879-fenderfredtag:fr.mathworks.com,2005:Question/3727682017-12-13T15:49:11Z2017-12-13T20:29:52ZHow can I plot multiple graphs from one set of table data, separated by NaN?<p>I have a table as below:
M=</p><pre class="language-matlab">NaN NaN
2 3
NaN NaN
NaN NaN
15 6
6 7
3 12
38 17
9 59
NaN NaN
10 129
11 34
9 5
NaN NaN
NaN NaN
NaN NaN
</pre><p>Goal: I am trying to plot graphs from each set of data, that is separated by the NaNs</p><p>E.g. for the data below a graph with x=2, y=3
Then a graph with x=15, 6, 3, 38, 9, y=6, 7, 12, 17, 59 respectively</p><p>Overall goal: to find the slope of each set of data and plot the slopes as a frequency distribution</p><p>Thank you!</p>Shravani Kakarlahttps://fr.mathworks.com/matlabcentral/profile/authors/6948646-shravani-kakarlatag:fr.mathworks.com,2005:Question/3711802017-12-05T12:28:22Z2017-12-13T20:27:19ZWhat is the unit of the translation component of the procrustes algorithm/function?<p>I use the procrustes function for two matrices and I want to get the translational component. I have the vector for the translational component, but I want to know the unit of the vector? Is it the same is my input? So if I have a matrix with positions in millimeters, my translational component is also in millimeters?</p>Annehttps://fr.mathworks.com/matlabcentral/profile/authors/3038413-annetag:fr.mathworks.com,2005:Question/3728232017-12-13T20:25:20Z2017-12-13T20:25:20Zmultiple barh plot with different base value settings in the same graph<p>Is there any way to have multiple horizontal bar plots in the same figure with different base value settings?</p><p>simply typing the following does not work properly. what I want is multiple separate horizontal bar charts starting at different positions in the same plot.</p><pre class="language-matlab">barh([5,10,15,20],[550,150,220,120],'BaseValue',260);
hold on
barh([5,10,15,20],[55,150,22,12],'BaseValue',26);
</pre><p>I figure I am missing something obvious, I hope</p><p>thanks
Greg</p>Gregory McFaddenhttps://fr.mathworks.com/matlabcentral/profile/authors/8207521-gregory-mcfaddentag:fr.mathworks.com,2005:Question/3721092017-12-10T01:05:53Z2017-12-13T20:23:24ZHow to expand 3D line in 2D directions?<p>I have a <b>xyz=17x3</b> array which forms an open square shape. I want to expand the shape (inside <b>or</b> outside only) with respect to <b>xy_directions only</b> and get a new array <b>xy=17x2</b> . So I can add the third column (Z) to the new array <b>xy</b> from the original array <b>xyz</b> and end up with a third array <b>XYZ1=17x3</b>. where * <b>XYZ1=[xy(:,1),xy(:,2),xyz(:,3)]*</b>.
In this case, I end up with expanded shape in xy_directions but keep (Z) fixed.(which I'm wishing for)</p><p>I tried the function <b>expandPolygon</b> from <b>geom2d</b>. But the output array has some rows filled with (Inf) instead of numbers, even though it has the same length as original array xyz.</p><p>Hope you can help me with that
Thank you so much..</p>Faez Alkadihttps://fr.mathworks.com/matlabcentral/profile/authors/3644876-faez-alkaditag:fr.mathworks.com,2005:Question/3724532017-12-12T00:40:10Z2017-12-13T20:23:14ZE-plane and H-plane patterns of a rectangular microstrip patch<p>I am trying to recreate a polar plot of gain in dB, but I am not sure how to create the graph. Any help is appreciated. This is what I have so far:</p><pre> if true
% code
% the following values are given on page 836
dielectric_const = 2.2; % unitless
h = 0.1588; % in cm
f = 10e9; % in Hz
L = 0.906; % in cm
L_e = 1.068; % in cm
E0 = 1; % in V/cm, generic value of 1 given
V0 = h*E0; % in V
theta = pi/2; % in radians
k0 = (2*pi*f)/(3e8); % wavenumber
W = 1.185; % width in cm
phi = linspace(0, pi/2, 1e3);
theta = pi/2;
r = 1;
a = (k0*h)/2;
b = (k0*L_e)/2;
c = k0*W;
d = c/2;
e = cos(phi);
f = sin(phi);
multiplier = i*(c*V0*exp(-1*i*k0*r)/pi*r);
n_1 = sin(a*e);
n_2 = cos(b*f);
d_1 = a*e;
% E plane, eq. 14-45
E_phi = (multiplier.*n_1.*n_2)./d_1;
end</pre>Maximiliano Rodallegashttps://fr.mathworks.com/matlabcentral/profile/authors/11730145-maximiliano-rodallegastag:fr.mathworks.com,2005:Question/3728212017-12-13T20:22:19Z2017-12-13T20:22:19ZReading only rows that start with scientific notation numbers in a text file<p>I'm a beginner in MATLAB and I'm trying to read only rows that start with scientific notation numbers (see attached file).
If you note, the original txt file contains "," instead ".", so I used the following code to replace "," by ".":</p><pre> % Replacing "," for "."
initialfile = fileread('IONIZ.txt');
initialfile = strrep(initialfile, ',', '.');
fileID = fopen('IONIZ_w_comma.txt', 'w');
fwrite(fileID, initialfile, 'char');
fclose(fileID);</pre><p>Since the number of header lines may vary, I only need to read the lines that start with scientific notation numbers.
How can I do this?</p>Saulo Albertonhttps://fr.mathworks.com/matlabcentral/profile/authors/11745173-saulo-albertontag:fr.mathworks.com,2005:Question/3728052017-12-13T18:59:51Z2017-12-13T20:08:11Zhow to use the for loop to simplify my array ? But I got the error In an assignment A(:) = B, the number of elements in A and B must be the same.<p>Hi , I try to use the matlab to express Xall</p><pre class="language-matlab">X1 = X + S(1,1)
</pre><pre class="language-matlab">X2 = X + S(2,1)
</pre><pre class="language-matlab">X3 = X + S(3,1)
</pre><pre class="language-matlab">X4 = X + S(4,1)
</pre><pre class="language-matlab">X5 = X + S(5,1)
</pre><pre class="language-matlab">X6 = X + S(6,1)
</pre><pre class="language-matlab">X7 = X + S(7,1)
</pre><pre class="language-matlab">X8 = X + S(8,1)
</pre><pre class="language-matlab">X9 = X + S(9,1)
</pre><pre class="language-matlab">X10 = X + S(10,1)
</pre><pre class="language-matlab">X11 = X + S(11,1)
</pre><pre class="language-matlab">X12 = X + S(12,1)
</pre><pre class="language-matlab">X13 = X + S(13,1)
</pre><pre class="language-matlab">X14 = X + S(14,1)
</pre><pre class="language-matlab">X15 = X + S(15,1)
</pre><pre class="language-matlab">X16 = X + S(16,1)
Xall = [X1;X2;X3;X4;X5;X6;X7;X8;X9;X10;X11;X12;X13;X14;X15;X16];
</pre><p>but I don't know how to use for loop to simplify it</p><p>I tried the</p><pre class="language-matlab">for n = 1:16
</pre><pre class="language-matlab">X(n) = X + S(n,1)
</pre><pre class="language-matlab">end
</pre><p>but it says A(:) = B, the number of elements in A and B must be the same.</p>Yiqing Zhouhttps://fr.mathworks.com/matlabcentral/profile/authors/6962700-yiqing-zhoutag:fr.mathworks.com,2005:Question/3728172017-12-13T20:07:09Z2017-12-13T20:07:09ZHi all, i have fitted a Four Parameters Logistic Regression for my X and Y data. i want to find the local slope of each data point, i would appreciate if somebody can help me on this , the attached image shows the fit<img src = "/matlabcentral/answers/uploaded_files/98465/Example_fit%20.jpg">Duminda Vidana Gamagehttps://fr.mathworks.com/matlabcentral/profile/authors/6393110-duminda-vidana-gamagetag:fr.mathworks.com,2005:Question/3728162017-12-13T20:06:40Z2017-12-13T20:06:40ZPassing string as function variable for renaming table column<p>I am trying to pass a string variable to a custom function to rename a table column title.</p><p>My code is below:</p><pre class="language-matlab">temperature = 'OPC.Temperature.BottomTemperature';
temp_column_name = 'Temperature';
</pre><pre class="language-matlab">%extract bottom temperature data
data_temp = dataextract(data_temp,temperature,temp_column_name);
</pre><p>Below is the function:</p><pre class="language-matlab">function [ data ] = dataextract( data_array,variable,column_name )
%remove all rows not containing variable in column 2
data_string = variable;
data_comp = strcmp(data_array(:,2),data_string);
data_comp = ~data_comp;
data_array(data_comp,:) = [];
</pre><pre> %remove extra information from columns 3 & 4 from data array
data_array(:,(2:4)) = [];</pre><pre> %convert data_array cell array to table
data_array = array2table(data_array,'VariableNames',{'TimeStamp', column_name});</pre><pre> %convert timestamp string to datetime
data_array.TimeStamp = datetime(data_array.TimeStamp,'InputFormat','yyyy-MM-dd HH:mm:ss.SSS');</pre><pre> %convert beam current string to double precision value
data_array.column_name = str2double(data_array.column_name);</pre><pre> data = data_array;
end</pre><p>I tried to initially just pass 'Temperature' in the function but that would not work and now a variable won't pass either. Below is my error:</p><pre class="language-matlab">Error using dataextract (line 18)
Unrecognized variable name 'column_name'.
</pre><pre class="language-matlab">Error in parser_test (line 38)
data_temp = dataextract(data_temp,temperature,temp_column_name);
</pre>jcledfo2https://fr.mathworks.com/matlabcentral/profile/authors/4499384-jcledfo2tag:fr.mathworks.com,2005:Question/3726732017-12-13T05:28:21Z2017-12-13T20:01:13Zcoverting simulink to m-codes<p>I have built a Simulink model and I need to convert it to Matlab m-codes. how can I accomplish it?</p>hh jhttps://fr.mathworks.com/matlabcentral/profile/authors/8710791-hh-jtag:fr.mathworks.com,2005:Question/3728032017-12-13T18:42:59Z2017-12-13T19:56:34Z How Execute statements if else condition <p>Hello Dears
I have a Problem
i Want to make Plots with Matlab for many Excel Files.
but when i change The Excel File ,I must everytime change The Title , The Labels and Legends Manual
can you help me to Programming this think .
ich have a Idee but Matlab can not Executed it .
can someone help me Please i need that for my Thesis.
Thank you</p><pre> % filename='File1';
omega=xlsread(filename);%Matrix 10078*28
[z,s]=size(omega);
t=1:1:10080;% Time vector</pre><pre> if filename=='File1' %everytime i change a File Name but they have a same size
figure(f1)
V1=omega(:,16);
V2=omega(:,17);
V3=omega(:,18);
plot(t,V1,'displayName','L1-N RMS 1/2(1-cyc)Max(V)')
hold on
plot(t,V2,'displayName','L2-N RMS 1/2(1-cyc)Max(V)')
hold on
plot(t,V3,'displayName','L3-N RMS 1/2(1-cyc)Max(V)')
title('Compare the Current Harmonic ')
ylabel('I Max(A)' )</pre><pre> end</pre><pre class="language-matlab">if filename='File2.xlsx'
V1=omega(:,16);
V2=omega(:,17);
V3=omega(:,18);
plot(t,V1,'displayName','L1-N RMS 1/2(1-cyc)Max(V)')
hold on
plot(t,V2,'displayName','L2-N RMS 1/2(1-cyc)Max(V)')
hold on
plot(t,V3,'displayName','L3-N RMS 1/2(1-cyc)Max(V)')
title('Compare the Voltage Harmonic L1 ')
ylabel('U Max(v)' )
</pre><pre class="language-matlab">end
</pre>houssem chedlihttps://fr.mathworks.com/matlabcentral/profile/authors/10373479-houssem-chedlitag:fr.mathworks.com,2005:Question/3728102017-12-13T19:06:12Z2017-12-13T19:51:09Zanalyse aircraft vibration data<p>Hi
I'm looking for any help available I am new to matlab, for a project I'm going to analyse aircraft vibration is this anything anyone has done before? I have 2 hours worth of data from a triaxual accelerometer stored in excel it was sampled at 100HZ. how do I display this data.</p>Gavin Lewishttps://fr.mathworks.com/matlabcentral/profile/authors/11290612-gavin-lewistag:fr.mathworks.com,2005:Question/3616162017-10-16T20:03:54Z2017-12-13T19:51:01ZM-file edited and saved by external editor is not recognized by MATLAB<p>Below code creates a reset button. When I change the szx variable in notepad++ and press reset button on the gui, the gui size does not change. I have to click run button on MATLAB editor to apply changes.
How can I make MATLAB recognize changes made in an external editor. I tried all the suggestions on these forum, like rehash. Nothing works.</p><pre class="language-matlab">function gui_ind
clear,clc,close all
f1=figure(1)
scr_sz=get(0,'ScreenSize')
szx=200
szy=300
posx=130;
posy=scr_sz(4)-60-szy;
set(gcf,'position',[posx posy szx szy]);
</pre><pre class="language-matlab">rst_b = uicontrol('string','Reset','style','pushbutton','position',...
[szx-60 0 60 20],'callback',{@rst_e_cbf});
</pre><pre class="language-matlab">px=0;py=szy;
</pre><pre class="language-matlab">VA_t = uicontrol('string','VA','style','text','position',[5 szy-20 30 18],...
'HorizontalAlignment','left');
VA_e = uicontrol('string','','style','edit','position',[25 szy-20 60 20],...
'callback',{@VA_e_cbf},'HorizontalAlignment','left');
</pre><pre class="language-matlab">function rst_e_cbf(varargin)
gui_ind()
end
</pre><pre class="language-matlab">end
</pre>mehmethttps://fr.mathworks.com/matlabcentral/profile/authors/1832213-mehmettag:fr.mathworks.com,2005:Question/3728152017-12-13T19:48:35Z2017-12-13T19:48:35ZPrediction using Neural network time series toolbox MATLAB<p>I am forecasting load using Neural network time series toolbox in MATLAB. I want to know how do I predict future load after training the network. In short, I want to know the commands which will predict future load using my input data after I am done training my network.</p>NMhttps://fr.mathworks.com/matlabcentral/profile/authors/10656152-nmtag:fr.mathworks.com,2005:Question/3728142017-12-13T19:47:00Z2017-12-13T19:47:00ZHow do I calculate the sum-of-squares error criteria (SSE) for my PID controller?<p>I have designed several PID controller using Simulink, now I need to compare the performances of the controllers by calculating the sum-of-squares error criteria (SSE), for all controllers designed. I have attached a copy of one of my systems; I'd appreciate some guidance on how to perform SSE?</p>hoomsn samivandhttps://fr.mathworks.com/matlabcentral/profile/authors/9634794-hoomsn-samivandtag:fr.mathworks.com,2005:Question/3728112017-12-13T19:24:06Z2017-12-13T19:46:41ZHow can i decode(unpack) an array of bits with a constant value?<p>For example;
I have an array; [0 0 0 1 1 1 0 0 0]. and a constant value L= 3
how can i get the output as; [0 1 0] ?</p>Ataberkhttps://fr.mathworks.com/matlabcentral/profile/authors/11745016-ataberktag:fr.mathworks.com,2005:Question/3728132017-12-13T19:46:26Z2017-12-13T19:48:51ZHow to save text files to a different folder than read?<p>I have a lot of files that I need to process of the form "abcdef - ###.txt" where ### can be anywhere from 4 to 9 sequence of random numbers. I have some code that is reading each file using dlmread in a for loop. Each file will get modified in some way and eventually will be left with multiple matrices that I want to output each to a new .txt file in a separate folder from where I'm getting the data from that looks like "abcdef - ###_x.txt", "abcdef - ###_x.txt" etc... where x is 1:number of matrices extracted</p><p>I was able to use sprintf('%s_%d,filename,x) to get dynamic variable naming for the matrices but I can't figure out how to write (dlmwrite is what I tried) each matrix to a new file dynamically.</p><p>myDirectory = uigetdir; %open directory</p><p>myFiles = dir(fullfile(myDirectory,'*.txt')); %get files in folder</p><p>for k = 1:length(myFiles) %loop through each file in myFiles</p><pre> baseFileName = myFiles(k).name;</pre><pre> filename = fullfile(myDirectory, baseFileName); </pre><pre> fprintf(1, 'Now reading %s\n', filename);</pre><pre> data=dlmread(filename,'',1,0); %build data matrix from file</pre><pre> filename=filename(1:end-4); %remove .txt from filename string</pre><pre> [rows,cols] = size(data); %</pre><pre> data_ext = data(:,[1,2,4]); %Extract time, flowrate (AU), concentration (AU)</pre><pre> numInjections = 0; </pre><pre> prevInjecting = false;</pre><pre> injectionData = []; %Empty injection array</pre><pre> for i=1:rows %index from 1 to #rows</pre><pre> currentFlow = data_ext(i,2); %flow at index i</pre><pre> if currentFlow > 5 && ~prevInjecting %is flow @ i > 5 and not previously?
numInjections = numInjections+1; %increase injection count
prevInjecting = true; %injection status: ON
injectionData(1,:) = data_ext(i,:); %% begin building array
elseif currentFlow > 5 && prevInjecting %if not beginning of injection
injectionData = [injectionData;data_ext(i,:)]; %% amend injection array with rows
elseif currentFlow <= 5 && prevInjecting %end of injection
%
injectionData(:,2)=injectionData(:,2).*(0.1/1024); %convert from AU to L/min
injectionData(:,3)=injectionData(:,3).*0.005-.1584; %convert from AU to g/L</pre><pre> %take this array and count with # of injections
filename_inj = sprintf('%s_%d.txt',filename,numInjections);</pre><pre> %dlmwrite(filename_inj,injectionData,'delimiter','\t');% write data to .txt file</pre><pre> injectionData = []; %reset injection data array,
prevInjecting = false; %injection status: OFF</pre><pre> else
prevInjecting = false; %injection status: OFF
end
end</pre><p>end</p>Chrishttps://fr.mathworks.com/matlabcentral/profile/authors/6034316-christag:fr.mathworks.com,2005:Question/3725592017-12-12T13:38:00Z2017-12-13T19:45:12ZPDE Toolbox thermalProperties() function handles<p>Is it possible to define the thermal characteristics (ThermalConductivity, MassDensity and SpecificHeat) of a 3D geometry as functions that depend on the position within the geometry?</p>David Naviauxhttps://fr.mathworks.com/matlabcentral/profile/authors/11654400-david-naviauxtag:fr.mathworks.com,2005:Question/1286122014-05-07T02:01:48Z2017-12-13T19:35:55ZHow can I fix an 'index out of bounds because size' when the array is the right size?<p>When I try to run my program I get the error "Attempted to access x(1,2); index out of bounds because size(x)=[4,1].". I have checked the size of x using size(x), and I get [4,2]. Why would MATLAB be reading the size differently? Is there an error somewhere(or everywhere) in my code?</p><p>Here are my m files and the error</p><img src = "/matlabcentral/answers/uploaded_files/12348/main.png"><img src = "/matlabcentral/answers/uploaded_files/12347/model.png"><img src = "/matlabcentral/answers/uploaded_files/12349/error%20with%20size.png">Alexanderhttps://fr.mathworks.com/matlabcentral/profile/authors/4648147-alexandertag:fr.mathworks.com,2005:Question/3727932017-12-13T17:12:08Z2017-12-13T19:34:48ZR2016a Why my title don't centralize?<p>Hi,</p><p>I started using the matlab R2016a recently and the title of my figures are not getting centralized. How can I fix this?</p>Leilane Passoshttps://fr.mathworks.com/matlabcentral/profile/authors/11163127-leilane-passostag:fr.mathworks.com,2005:Question/3727902017-12-13T16:57:47Z2017-12-13T19:33:10ZIs it possible to disable or get warnings when using .* on mismatched vectors?<p>I've finally moved up from 2014b and I see there is a new feature(s) that lets you do math operations that would have previously resulted in errors. For example, you can now use .* on vectors of different shapes. I can see how this could be handy sometimes, but in practice, I lose track of whether a vector is a row or column and instead of getting an error, MATLAB makes a big matrix and moves on. In bad cases, the math to follow is also valid resulting in weird answers. Is there a way to at least have this give out a warning?</p>Chuck37https://fr.mathworks.com/matlabcentral/profile/authors/2235717-chuck37