https://jp.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — 新規の質問2018-06-22T15:20:55Ztag:jp.mathworks.com,2005:Question/4069552018-06-22T14:22:42Z2018-06-22T15:20:55ZHow to find the x-coordinate for the maximum value(peak) in a plot?I have an FFT plot for a vibration data of a bridge as shown in the figure.I want to know at which frequency(x-axis) the amplitude(y-axis) is maximum to find critical frequency.<img src = "/matlabcentral/answers/uploaded_files/122405/Screenshot%20(96).png"><p>fs=2000;
T=1/fs;
Length='what is the length?';
L=input(Length);
t=(0:L-1)*T;
ACC='which matrix has the acceleration data?';
accdata=input(ACC');
y=fft(accdata);
p2=abs(y/L);
p1=p2(1:L/2+1);
p1(2:end-1)=2*p1(2:end-1);
f=fs*(0:(L/2))/L;
plot(f,p1)
xlabel('frequency(Hz)')
ylabel('Amplitude')</p>Karthikeyan Karuppusamyhttps://jp.mathworks.com/matlabcentral/profile/authors/10920979-karthikeyan-karuppusamytag:jp.mathworks.com,2005:Question/4069472018-06-22T13:19:26Z2018-06-22T15:20:51Ztable block growth slow<p>Hi,</p><p>I am trying to fill up a table with mixed data containing cashflows. each mortgage gets multiple lines. Preallocation of a similair table does not seem solve this problem. For preallocation i used repmat to create a table as large as the output containing dummy vars. Because dynamic allocation is complexer to read and gave no performance boost I decided to drop this approach.</p><p>The process of dynamically building the table starts out fairly fast but after 35000 iterations, where each adds blocks of about 360 new records, the perfomance decreases very fast. Takes about an hour or more.</p><pre> enddataset = [dataset;newblock] % dynamic, slows over time</pre><p>the tictoc slows down. now the weird stuff it that when I use struct it remains fast (11/12 minutes):</p><pre> myStruct.iterationLabel = newblock. % does not slow over time</pre><p>As I said using repmat and preallocation does not speed up.</p><p>Is it possible to grow a table in a fast manner?</p>Alex Bhttps://jp.mathworks.com/matlabcentral/profile/authors/2872347-alex-btag:jp.mathworks.com,2005:Question/4069692018-06-22T15:19:01Z2018-06-22T15:19:01ZStep response of Estimated model in SID toolbox.<p>Hello, I am trying to find model of my system using matlab's system identification toolbox. why i get step response of estimated model which settles at 0.05 instead of 1. Model shows good fit to validation data but residual analysis is bad. Thanks.</p>Amaresh Mandalhttps://jp.mathworks.com/matlabcentral/profile/authors/11854004-amaresh-mandaltag:jp.mathworks.com,2005:Question/4069572018-06-22T14:25:47Z2018-06-22T15:17:03Zhow to change variable value from another function<p>Hi,
is there any way to change the value of a and b without change the function's signature.
like global variable in c?</p>yon amhttps://jp.mathworks.com/matlabcentral/profile/authors/10411473-yon-amtag:jp.mathworks.com,2005:Question/4069682018-06-22T15:14:50Z2018-06-22T15:14:50ZProcessor-in-the-loop Arduino simulation with double data type<p>I want to perform processor in the loop simulations of a subsystem (controller) in my model on an Arduino Uno board. I successfully generate a PIL block, however I run into the following error message when I start the simulation:</p><pre> Data type "double" is not supported for SIL or PIL execution with the current target configuration. This is because the host size (8 bytes) and target size (4 bytes) do not match. To avoid this error, do not use this data type at the component interface.</pre><p>I've tried using the single precision conversion tool with no effect and also tried surrounding the subsystem with the respective conversion blocks.</p>Kaloyan Yordanovhttps://jp.mathworks.com/matlabcentral/profile/authors/11140825-kaloyan-yordanovtag:jp.mathworks.com,2005:Question/4069162018-06-22T08:35:17Z2018-06-22T15:09:41ZHow can I simulate motion blur due to camera and object movement?<p>Hi, I want to simulate motion blur of an image due to camera and object movement. I know I can use the MATLAB function fspecial so blur the image due to camera movement since the function applies the same 2D filter to the whole image which is exactly what happens when there is camera movement (e.g. the whole image is blurred). But in the case of motion blur due to object movement only part of the image is blurred since the background is stationary. What is the easiest method of simulating motion blur due to a moving object? I want to combine it with the motion blur due to camera movement. This in effect means that the image will be blurred to a "greater" extend in the region of the object than in the background (e.g. The background will ONLY have motion blur due to camera movement and the region of the object will have a COMBINED motion blur due to camera and object movement). An answer to an efficient way of combining the 2 types of motion blur (e.g. motion blur due to camera and object movement) will also be appreciated.</p><p>Regards
Johann Berrangé</p>Johann Berrangéhttps://jp.mathworks.com/matlabcentral/profile/authors/13054801-johann-berrangetag:jp.mathworks.com,2005:Question/4069432018-06-22T13:11:41Z2018-06-22T15:09:25ZHow to make a new matrix from find function results of different size <p>I have a matrix of IC 2008x1 that has values from 1 to 16 (some in between number might be missing) and I want to create a matrix that each column has the rows of the original matrix that correspond to each value 1 to 16
eg original matrix 4; 1; 3; 2; 5; 6; 4;
new matrix [2] [4] [3] [1;7] [5] [6]</p><p>I try to do this like this
for j=1:B</p><pre> k=find(IC==j);
F(:,j)=k;</pre><p>end
where B is 16 but it says that Subscripted assignment dimension mismatch.
Do you know an alternative that works regaldless of this mismatch?</p>Georgios Tertikashttps://jp.mathworks.com/matlabcentral/profile/authors/11056216-georgios-tertikastag:jp.mathworks.com,2005:Question/4069582018-06-22T14:31:31Z2018-06-22T15:06:53ZHow to make linear fit?<p>Hi;
I want to plot a linear fit for the graphic in the attached file.
And also I want to calculate slope of this linear fit?
How can I do this? File is in the attached file..
Thanks a lot.</p>nancyhttps://jp.mathworks.com/matlabcentral/profile/authors/5885586-nancytag:jp.mathworks.com,2005:Question/4069672018-06-22T15:06:45Z2018-06-22T15:06:45ZError when using matlab and labspec via activex as a bridge<p>Hi,
I try to use matlab and activex as a bridge to control labspec Raman spectrometer. I am able to load the activex driver in matlab R2007b (32 bit) with the command :</p><p>LabSpec=actxserver('NFACTIVEX.NFActiveXCtrl.1');</p><p>and use simple command like :</p><p>LabSpec.AboutBox;</p><p>This command open a dialog box with the version of the labspec software. However, when I'm asking for a more complex function, like moving the XYZ stage :</p><p>LabSpec.MoveMotor('X',0,'',0);</p><p>I got the following error : ??? Error: Object returned error code: 0x7941E804</p><p>Does someone have any clue to resolve that?</p>François Dionhttps://jp.mathworks.com/matlabcentral/profile/authors/13056383-francois-diontag:jp.mathworks.com,2005:Question/4068102018-06-21T16:06:07Z2018-06-22T15:06:25ZHow can I open a generic EXCEL file ?<p>Hi,</p><p>the procedure to access a spreadsheet data from MATLAB running an Excel application in an Automation server is well known and explained at the matlab Documentation. As an example, something like this is seen:</p><p>exl = actxserver('excel.application');</p><p>exlWkbk = exl.Workbooks;</p><p><b>exlFile = exlWkbk.Open([docroot '/techdoc/matlab_external/examples/input_resp_data.xls']);</b></p><p>I need to open a generic file from Excel (something you wold do otherwise at the Command Window through winopen(cd) ). I would like to have the possibility to chose the file and don't let it fix.</p><p>Thank you.</p>Fernandahttps://jp.mathworks.com/matlabcentral/profile/authors/12336997-fernandatag:jp.mathworks.com,2005:Question/4068752018-06-22T00:40:29Z2018-06-22T15:06:06Zspeed-up the given code<p>The following code is taking a most of the time in my script and I have to run the script many times Is there a way to reduce the time for its execution.</p><pre class="language-matlab">t=0:200000;
lambda=[1,2,3;4,5,6;7,8,9;10,11,12];
for trans=1:size(lambda,1)
uh_fun{trans}=expconv(lambda(trans,:));
end
</pre><pre class="language-matlab">uh=zeros(length(t),1);
for i=1:length(uh_fun)
temp_uh_fun=uh_fun{i};
f_gamma=zeros(length(t),1);
for j=1:length(temp_uh_fun)
f_gamma=f_gamma+temp_uh_fun{j}(t)'; % this line take a lot of time
end
uh=uh+p(i)*f_gamma; % p is an array of scalars
end
</pre><p>I have added expconv function for reference. I need some suggestions to improve the performance.</p>Abhinavhttps://jp.mathworks.com/matlabcentral/profile/authors/5297551-abhinavtag:jp.mathworks.com,2005:Question/4069442018-06-22T13:16:18Z2018-06-22T15:05:35ZMerge L and b channels in LAB color space <p>Is it possible to merge two channels in a color space other than RGB?</p>Mirett Boliardhttps://jp.mathworks.com/matlabcentral/profile/authors/13055185-mirett-boliardtag:jp.mathworks.com,2005:Question/4068122018-06-21T16:30:13Z2018-06-22T15:01:44ZHow can I open a generic (not defined) EXCEL file ? <p>Hello,</p><p>the procedure to access a spreadsheet data from MATLAB running an Excel application in an Automation server is well known and explained at the matlab documentation. At the Matlab documentation can be seen something like this:</p><p>exl = actxserver('excel.application');</p><p>exlWkbk = exl.Workbooks;</p><p><b>exlFile = exlWkbk.Open([docroot '/techdoc/matlab_external/examples/input_resp_data.xls']);</b></p><p>I am writing a code at GUIDe and I haven't found the code to load a generic excel file at a programm function ( something like winopen(cd) at the Command Window). There are other matlab functions like uiopen('-file'), but they dont load the file. Open does also not work because the file in that case has to be defined by the programmer. I need the file to be choosed by the end user.</p><p>Thank you.</p>Fernandahttps://jp.mathworks.com/matlabcentral/profile/authors/12336997-fernandatag:jp.mathworks.com,2005:Question/4069612018-06-22T14:37:29Z2018-06-22T15:01:20ZHow can i convert diameter of irregular object in pixel to mm, without drawing line again and again.. also i am not avaliable with the true height of the image in mm...???<pre> conversion from pixels to mm</pre>Savy Gulatihttps://jp.mathworks.com/matlabcentral/profile/authors/12422030-savy-gulatitag:jp.mathworks.com,2005:Question/4069662018-06-22T15:00:29Z2018-06-22T15:00:29ZHow Long stay MCR_CACHE_MEMORY in temp folder?<p>How Long stay MCR_CACHE_MEMORY in temp folder?</p>Selva Karnahttps://jp.mathworks.com/matlabcentral/profile/authors/4733665-selva-karnatag:jp.mathworks.com,2005:Question/4065892018-06-20T15:22:02Z2018-06-22T14:59:13ZHow to improve a Thz image quality ?<p>Hello everyone,</p><p>I'd like to know how to improve the image that comes from a terahertz camera with matlab ?
the image is linked, I also have a video, can I work on the video to improve the image?
Thanks in advance</p>newport portnewhttps://jp.mathworks.com/matlabcentral/profile/authors/13044640-newport-portnewtag:jp.mathworks.com,2005:Question/4069652018-06-22T14:59:05Z2018-06-22T14:59:05ZHow to reduce MCR_CACHE_SIZE ? from M.file or where ? can share Idea's?<p>How to reduce MCR_CACHE_SIZE ? from M.file or where ? can share Idea's?</p>Selva Karnahttps://jp.mathworks.com/matlabcentral/profile/authors/4733665-selva-karnatag:jp.mathworks.com,2005:Question/3929792018-04-06T01:55:18Z2018-06-22T14:58:41ZI need matlab code for calculation area of various nuclei in segmented image?<p>i need matlab code for total nuclei in the images</p>Amsinihttps://jp.mathworks.com/matlabcentral/profile/authors/11030400-amsinitag:jp.mathworks.com,2005:Question/4069592018-06-22T14:36:06Z2018-06-22T14:58:34ZI need help plss<p>Hey, i have a problem with this one: Write a function called light_speed that takes as input a row vector of distances in kilometers and returns two row vectors of the same length. Each element of the first output argument is the time in minutes that light would take to travel the distance specified by the corresponding element of the input vector. To check your math, it takes a little more than 8 minutes for sunlight to reach Earth which is 150 million kilometers away. The second output contains the input distances converted to miles. Assume that the speed of light is 300,000 km/s and that one mile equals 1.609 km.
and here's my answer:</p><pre class="language-matlab">function[TimeInMinutes,DistanceInMiles] =light_speed(DistanceInKm)
DistanceInKm=DistanceInKm(:);
TimeInMinutes=sum(DistanceInKm./((3e5)*60));
DistanceInMiles=(DistanceInKm./1.609);
end
</pre>ahmed yassinehttps://jp.mathworks.com/matlabcentral/profile/authors/12978562-ahmed-yassinetag:jp.mathworks.com,2005:Question/202011-01-06T00:28:46Z2018-06-22T14:50:54ZHow do I make a desktop launcher for MATLAB in Linux?<p>I don’t want to have to open a terminal window every time I want to launch MATLAB on Linux. I tried to make a Gnome launcher, but it does not seem to work. The command I gave was:</p>
<pre> /usr/local/bin/matlab &</pre>
<p>I see the process running, but now windows appear. What am I doing wrong?</p>Ian Jessenhttps://jp.mathworks.com/matlabcentral/profile/authors/1597502-ian-jessentag:jp.mathworks.com,2005:Question/4069382018-06-22T11:40:15Z2018-06-22T14:49:17ZFitting the numerical solution of a PDE with one parameter to some data<p>I need to fit the numerical solution of a PDE with one parameter to some data in MATLAB.</p><p>I already solved the PDE (by giving an arbitrary value to the parameter) and I have the data, but I am not sure if I can use <tt>nlinfit</tt>, since it requires an analytic function as input.</p><p>Another issue is how to pass the parameter to be fitted to <tt>pdepe</tt> to solve the PDE.</p>matnewbiehttps://jp.mathworks.com/matlabcentral/profile/authors/5913505-matnewbietag:jp.mathworks.com,2005:Question/4069642018-06-22T14:43:03Z2018-06-22T14:43:03Zopen_system modality<p>Hello all,
I have a script that opens up simulink block properties by using open_system. I want the script to wait till the user sets some properties or cancels the block properties window.</p><p>In other words, I want the block properties window to be blocking/modal. After the user presses ok or cancel, the script should continue.</p>EShttps://jp.mathworks.com/matlabcentral/profile/authors/4396345-estag:jp.mathworks.com,2005:Question/4069632018-06-22T14:42:53Z2018-06-22T14:42:53Z Initial conditions for the filter delays<p>How can I use initial conditions for the filter delays when I have to use filter function in matlab?</p><pre> [y1,zi] = filter(b,a,x1);
[y2]=filter(b,a, x2,zi) ;
y=[y1;y2];</pre><p>Is that what it should be?</p>hoda kazemzadehhttps://jp.mathworks.com/matlabcentral/profile/authors/12709122-hoda-kazemzadehtag:jp.mathworks.com,2005:Question/4069532018-06-22T14:09:41Z2018-06-22T14:42:22ZHow to perform Shapelet transform in MATLAB?<p>I am working on classification of the power quality disturbances. So, I wish to use Shapelet transform in MATLAB. Can anyone over here guide me through this.</p>Sudheer Naiduhttps://jp.mathworks.com/matlabcentral/profile/authors/10236892-sudheer-naidutag:jp.mathworks.com,2005:Question/4069622018-06-22T14:40:06Z2018-06-22T14:40:06ZWhy does matlab 2017b take 4 times as long as 2014a?<p>I am running this code on our university's supercomputer. Recently they updated their servers from using Matlab 2014a to 2017b. The code used to take 10-12 minutes to run with 2014, but now it takes 40 minutes. Using the tic and toc commands I can see that the part of the code that is taking longer is the following parfor. Has there been a significant change in how parfors are handled from 2014 to 2017? Thanks.</p><pre> tic
parfor i = 1:timeseries_info.end_time
if i<10
formatspec = 'y_gradient0000000%d.dat';
filename = sprintf(formatspec,i);
elseif i<100
formatspec = 'y_gradient000000%d.dat';
filename = sprintf(formatspec,i);
elseif i<1000
formatspec = 'y_gradient00000%d.dat';
filename = sprintf(formatspec,i);
else
formatspec = 'y_gradient0000%d.dat';
filename = sprintf(formatspec,i);
end</pre><pre> full_filename = strcat(location,filename)
time_steps(:,:,i+1) = import_full_data_set(full_filename);
end
toc</pre>Kyle Hakeshttps://jp.mathworks.com/matlabcentral/profile/authors/8496246-kyle-hakestag:jp.mathworks.com,2005:Question/2458852015-09-29T20:36:35Z2018-06-22T14:39:55ZSort stocks into portfolios based on two different stock characteristics<p>Hello,</p><p>I try to sort stocks into portfolios and calculate their market cap weighted porrfolio returns based on two different stock characteristics.
Suppose I have a Matrix A (180,400) with 180 (monthly) return timeseries of 400 different stocks.
Matrices B and C (both 15x400) contain two different characteristics of each company, but at different dates (yearly, therefore 15 rows).</p><p>All three Matrices contain NaNs.</p><p>Firms shall be yearly sorted into portfolios based on the yearly 5 quantiles (0.2:0.2:0.8) of each of the two characteristics.
Two different characteristics with 5 quantiles results in 5x5 = 25 portfolios each year.</p><p>I would be very delighted if anyone could give me some hints.</p><p>Please let me know if anyone of you had to solve the same problem in the past already.</p><p>Thank you very much in advance.</p>Christoph Kemmerhttps://jp.mathworks.com/matlabcentral/profile/authors/6974517-christoph-kemmertag:jp.mathworks.com,2005:Question/4069602018-06-22T14:36:58Z2018-06-22T14:36:58ZWhen importing Matlab files into CaGe from ATI, the imported 'table' is not the same as the exported calibration map. I am unsure what I am doing wrong or if there is a potential bug in the software. I dont beleive it is the export from ATI. <p>This happens for all 2D maps, but curves appear to be OK.</p>Phil Bakerhttps://jp.mathworks.com/matlabcentral/profile/authors/13056104-phil-bakertag:jp.mathworks.com,2005:Question/4066592018-06-20T20:46:30Z2018-06-22T14:35:34ZLoop to solve ODE45 multiple times?<p>Hello I made this loop to try to solve this system of diferential equations with different initial conditions but im not sure if is ok since im only obtaining a matrix of 45 values where I suppose to get more. This is my code</p><pre class="language-matlab">kba= 1;
kmax= 10000000;
r = 1;
co= 1;
for a = gen10m
for b = gen11m
for c = gen01m
for d = gen00m
</pre><pre> k= kba + kmax *(((b + a)/(a + b + c + d))*((b + c)/(a + b + c + d)));</pre><pre> f = @(t,x) [(r - (1 + 1) * co) * x(1) * (1 - ((x(1) + x(2) + x(3) + x(4))/k)); (r - (1 + 0) * co) * x(2) * (1 - ((x(1) + x(2) + x(3) + x(4))/k));
(r - (0 + 1) * co) * x(3) * (1 - ((x(1) + x(2) + x(3) + x(4))/k)); (r - (0 + 0) * co) * x(4) * (1 - ((x(1) + x(2) + x(3) + x(4))/k))];
[t,x] = ode45(f,[0 1],[a b c d]);</pre><p>gen10m,gen11m, etc...are vectors of the same size so I want to use eah value of these vectors as initial conditions and solved this system for all the values of the vector. Do you think my code is wrong? Or maybe I have to improve it and add a way to save the data each time it is solve for a particular initial conditions?</p>PAUL DAMIAN JIMENEZ NUÑOhttps://jp.mathworks.com/matlabcentral/profile/authors/13028273-paul-damian-jimenez-nunotag:jp.mathworks.com,2005:Question/4069512018-06-22T13:44:46Z2018-06-22T14:33:53Zhow i can perform this for loop<p>Hello
im trying to perform this cod 20 times but the for loop moves one time"j=1 instead of 20" could anyone please help me to solve it!</p><pre class="language-matlab">clear all
close all
clc
for j=1:20
c=[1 2 3 5 6 7 8 99 9 3 4 55 66 7 8 9 9 97 0 1 2 ];
for k=1:length(c)
if c(k)>=5
ag(k)=1
k1=k
return
elseif c(k)<=-1
ag(k)=0
k1=k;
return
else
end
end
m=k1
l(j)=sum(ag)
end
j
</pre>Tammun filistinhttps://jp.mathworks.com/matlabcentral/profile/authors/5789444-tammun-filistintag:jp.mathworks.com,2005:Question/2655392016-01-28T06:05:05Z2018-06-22T14:33:37ZCan I use DAQ Toolbox Adaptor kit to connect my device with Session-based DAQ Toolbox ?<p>Hi all ,</p><p>Can I use DAQ Toolbox Adaptor kit to connect my device with Session-based DAQ Toolbox ?</p><p>I found the document of DAQ Toolbox Adaptor kit updated for Matlab 2012.
And I just saw Legacy functions in the document.</p><p>So can I use DAQ Toolbox Adaptor kit to connect my device with Session-based DAQ Toolbox ?
How ? Any Document ?
Or others ?</p><p>Thanks</p>Kev Chenhttps://jp.mathworks.com/matlabcentral/profile/authors/7549316-kev-chentag:jp.mathworks.com,2005:Question/4069352018-06-22T11:25:38Z2018-06-22T14:29:45ZHow do I find the value at which the pH curve stops being linear (around 10.5)?<img src = "/matlabcentral/answers/uploaded_files/122384/titration%20naoh.jpg"><p>I'd like matlab to return the value of the pH at which the relationship between pH and volume stops being linear. My idea was to calculate the second derivative of the function and return the value at which it is not equal to 0, however given the previous loop pH is just values rather than an equation. Any help would be appreciated. I have attached the graph produced by matlab, as well as the relevant part of the code.
if true
T = 293; %input('Enter system temperature in Kelvin (293-303 K domain for Henrys) = ');% K</p><p>%% Amount of CO2 dissolved in system is fixed and given by Henry's law as a function of temperature.
H_w = 3.54.*10^(-7).*exp(2044./T);% Henry's constant - mol/(m3 Pa)</p><p>%% Correction to account for salting-out effect.
% Initial assumptions as to concentration of ions. kmol/m3 (Based on a pH of 14 and concentration of ions due to dissociation extent
% of CO2 dissolved)
Na = 1;
OH_1 = Na;
HCO3_1 = 2.87329895849083e-09;
CO3_1 = 0.0000134394289431007;
% Constants from Weisenberger paper.
Na_h = 0.1143; % m3/kmol
OH_h = 0.0839; % m3/kmol
HCO3_h = 0.0967; % m3/kmol
CO3_h = 0.1423; % m3/kmol
CO2_h = -0.0172 -0.338e-03.*(T - 298.15); % m3/kmol</p><p>% Corrected Henry's law coefficient:
H_co2 = H_w * 10.^(-Na*(Na_h + CO2_h)-OH_1*(OH_h + CO2_h)-HCO3_1*(HCO3_h + CO2_h)-CO3_1*(CO3_h + CO2_h));
%% Enter CO2 ppmv in air
CO2_ppm =350 ;%input('Enter concentration of CO2 in air in ppm = ');
CO2_air = 350./10^(6); % volume of CO2 in atmospheric air
% Atmospheric pressure in Pa
p_atm = 101325; %Pa
% partial pressure of CO2
pp_CO2 = p_atm .* CO2_air;
% Concentration of dissolved CO2:
CO2_d = (pp_CO2 .* H_co2)/1000
k1 = exp(-12092.1./T - 36.786*log(T) + 235.482); % kmol m-3
kw = exp(148.9802 - 13847.26/T - 23.6521*log(T));
k2_inf = 10^(1568.94/T + 0.4134 -0.00673 * T);
% As can be seen it depends on the concentration of Sodium ions, fixed by
% the concentration of the aqueous solution in absorber.
k2b = k2_inf * 10^((1.01*sqrt(Na)/(1 + 1.27*sqrt(Na))) + 0.125 * Na);
k1b = k1./kw;
v_base = 220; %l
v_max = 150000000; % l</p><p>dx = 1000000;
x = 0:dx:v_max;
n_base = Na * v_base;
OH_final= 0;</p><p>for i =1:1/dx*v_max +1
%calculate differential amount of mols of acid added
na0 = x(i)*CO2_d;
%calculate new total volume
v = v_base + x(i);
% calculate resultant number of moles of OH- as a result of neutralisation</p><pre> if OH_final == 0 'OR' == 1;
nb0 = n_base ;
else nb0 = n_base - (v-(i-1)*dx)*(OH_final);
end</pre><pre> % solve for the change from initial to equilibrium conditions for
% reaction 1
syms x1 x2
OH_1 = vpasolve(k1b*(CO2_d*x(i)-x1)*(nb0-x1) - x1*v, x1);
%OH_1 = min(OH_1(OH_1==real(OH_1) & OH_1>=0 & OH_1<=na0));
OH_1 = min(OH_1(OH_1==real(OH_1) & OH_1>=0 & OH_1<=min(na0,nb0)));
% solve for the change from initial to equilibrium conditions for
% reaction 2
nb1 = nb0-OH_1;
OH_2 = vpasolve((OH_1-x2)*(nb1 - x2)*k2b - x2*v, x2);
OH_2 = min(OH_2(OH_2==real(OH_2) & OH_2>=0 & OH_2<=min(OH_1,nb1)));</pre><pre> OH_final = (Na*v_base - OH_1 - OH_2)/ v;</pre><pre> pH1(i) = -log10(kw) - -log10(OH_final);</pre><p>end</p><p>option3 = input('Do you wish to print titration curve? 1=yes, 2=no ');
if option3 == 1;
figure(3)
plot(x,pH1,x, 'r')
xlabel('Amount of acid added (l)')
ylabel('pH')
title('NaOH titration with carbonic acid')
else
end
end</p>Jose maria morenetehttps://jp.mathworks.com/matlabcentral/profile/authors/6803455-jose-maria-morenetetag:jp.mathworks.com,2005:Question/4053812018-06-13T01:53:28Z2018-06-22T14:27:53Zhow to solve transcedental equation in matlab<p>I am practicing solving the next transcendental equation in matlab</p><pre class="language-matlab">(a/c)*sqrt((b*m1)^2-(p*c)^2)-atan( sqrt(( (p*c)^2-(b*m2)^2 ) /( (b*m1)^2-(p*c)^2 ) ) )-atan( sqrt(( (p*c)^2-(b*m3)^2 ) /( (b*m1)^2-(p*c)^2 ) ) ) == r*pi
</pre><p>here</p><pre class="language-matlab">a=1x10^-6;
c= 3x10^8;
m1=2.2;
m2=1.5;
m3=1;
</pre><p>I was trying to plot "p" vs "b" where "b" runs from 0 to 3x10^15 and r is a parameter that takes values of 0, 1 and 2. I already tried all day but I cannot find solution, I tried with fzero(fun,xo) without success, can you give any suggestion?</p>alburary danielhttps://jp.mathworks.com/matlabcentral/profile/authors/12996088-alburary-danieltag:jp.mathworks.com,2005:Question/4069562018-06-22T04:00:00Z2018-06-22T14:25:03ZDoes MATLAB support High DPI screens on Linux?<p>I am running MATLAB on Linux on a high resolution 4K display. The menus, menu bar, etc are very small and the characters are difficult to read because of their small size. I have already changed the font size in the editor and command window, but I cannot find any way of changing the MATLAB program menu bar size.</p>MathWorks Support Teamhttps://jp.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:jp.mathworks.com,2005:Question/4068622018-06-21T21:31:05Z2018-06-22T14:24:44ZIs there something in MATLAB called de-sample? and how to do it? <p>If I have:</p><p>Time = [1:10];</p><p>Signal = [0 1 1 1 2 3 3 4 5 5];</p><p>Is there a piece of code to eliminate the repeated samples in the signal (which is called "de-sample") without changing the shape of the signal?!</p>Amr mshttps://jp.mathworks.com/matlabcentral/profile/authors/10216631-amr-mstag:jp.mathworks.com,2005:Question/4069342018-06-22T11:05:37Z2018-06-22T14:21:27Zxlswrite text with multiple empty cells inbetween<p>I have ratio data for multiple markets and would like to write them to excel, as the sequence of ratios stays the same I just write the Header2 multiple times. For the top row however there should be, in this case, four empty cells inbetween the market titles. I have another case where I need 20 empty cells inbetween each title. Is there a shorter way to do this?</p><pre class="language-matlab">Ratios = [PB, PE, EVEBITDA, PFCF, ROE];
RatiosD = [PB, PE, EVEBITDA, PFCF, ROE];
RatiosE = [PB, PE, EVEBITDA, PFCF, ROE];
</pre><pre class="language-matlab">Header1 = {'All,'','','','' 'Developed','','','','' 'Emerging'};
Header2 = {'PB', 'PE', 'EVEBITDA', 'PFCF', 'ROE'};
</pre><pre class="language-matlab">xlswrite('Ratios.xlsx', [Header1], 'Ratios', A1);
xlswrite('Ratios.xlsx', [Header2, Header2, Header2], 'Ratios', A2);
xlswrite('Ratios.xlsx', [Ratios, RatiosD, RatiosE], 'Ratios', A3);
</pre>Christian Egolfhttps://jp.mathworks.com/matlabcentral/profile/authors/6867689-christian-egolftag:jp.mathworks.com,2005:Question/960052012-02-27T22:41:00Z2018-06-22T14:19:43ZWhy do I get the error "Undefined function or variable"?<p>I am receiving the following error message, how can I resolve this issue?</p><pre class="error"> ??? Undefined function or variable ‹FunctionName›
??? Undefined function or method ‹FunctionName› for input arguments of type ‹ClassName›.</pre>MathWorks Support Teamhttps://jp.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:jp.mathworks.com,2005:Question/4067452018-06-21T11:32:40Z2018-06-22T14:19:25Zhow to solve error between theoretical curve and experimental curve?<p>hi
I am working on a project and my project manager gave me a Matlab code and asked me to find why theoretical data is not matching with experimental data and solve if there is an error. I tried but I am unable to do it. can anyone help me?</p><img src = "/matlabcentral/answers/uploaded_files/122229/Capture.PNG">Kartheek Reddeddihttps://jp.mathworks.com/matlabcentral/profile/authors/9702645-kartheek-reddedditag:jp.mathworks.com,2005:Question/4065692018-06-20T14:55:17Z2018-06-22T14:17:21ZQuestion about regionprops3 'Orientation' angles / origin<p>I want to find out the spatial orientation of an object in a 3D image stack. For this, I am using regionprops3 of the Image Processing Toolbox. However the "order" of x-y-z angles confuses me, as the description sais "The angles are based on the right-hand rule. regionprops3 interprets the angles by looking at the origin along the x-, y-, and z-axis representing roll, pitch, and yaw respectively." Does this mean, the origin is at the lower front right corner of my image stack?</p><p>So my question is, can someone please help me translate the x-y-z angles into my image stack coordinate system, where the origin is at the top-left corner, y/rows goes down, x/columns to the right and z/pages "towards you"? As far as I figured, the "x" angle of regionprops seems to refer to what's my "Z"? Thanks a lot.</p>Isabel Ottmannhttps://jp.mathworks.com/matlabcentral/profile/authors/12659887-isabel-ottmanntag:jp.mathworks.com,2005:Question/3755152018-01-04T07:14:24Z2018-06-22T14:14:36ZEstimation of Pitch from Speech Signals Using Autocorrelation Algorithm<p>Hello,</p><p>I want to detect speech signals pitch frequency using autocorrelation algorithm. I have a MATLAB code but the results are wrong. I would be grateful if you could solve the mistake in my code.</p><pre class="language-matlab">[y,Fs]=audioread('Sample1.wav');
y=y(:,1);
auto_corr_y=xcorr(y);
subplot(2,1,1),plot(y)
subplot(2,1,2),plot(auto_corr_y)
[pks,locs] = findpeaks(auto_corr_y);
[mm,peak1_ind]=max(pks);
period=locs(peak1_ind+1)-locs(peak1_ind);
pitch_Hz=Fs/period
</pre><p>Thank you for your help in this matter.</p>JAMES SMITHhttps://jp.mathworks.com/matlabcentral/profile/authors/11848084-james-smithtag:jp.mathworks.com,2005:Question/4057152018-06-14T16:00:24Z2018-06-22T14:14:27ZHow to use a deep learning approach to recognize and track objects in a live video feed?<p>Hello! So I have worked out and understand how to program MATLAB to recognize an object in an image, but what would the process be for now recognizing that object in a live video feed? (We are trying to automate our microscope so that it can find and track single cells)
Don't necessarily need specific code if that's too much trouble but just tips on what to do, thanks guys! I appreciate it.</p><p>-Alec</p>Kevin Petersenhttps://jp.mathworks.com/matlabcentral/profile/authors/12816951-kevin-petersentag:jp.mathworks.com,2005:Question/4069542018-06-22T14:13:37Z2018-06-22T14:13:37ZHow to detect the change point<pre> Hi,
I want to detect the change point for example in the below data:</pre><pre> -32526
-32526
-32526
-32526
-32526
-32526
-32526
-32526
-25123
-25123
-25123
-25123
0.25
12562
32526
32526
32526
12326
-32526
-32526
-32526
-25123
1203
23562
32526
32526</pre><pre class="language-matlab">its a time series data, and one data per sec.
</pre><pre class="language-matlab">I want to detect the change point, but there are small changes like 8 sec, but I want to catch if the change (in %) is >50% within 3~5 seconds. that is like at 12th second.
</pre><pre class="language-matlab">I use the below code, but don't know exactly how to catch what I want.
</pre><pre class="language-matlab">[~,~,data]=xlsread('findPeaksInput.xlsx');
data=cell2mat(data);
diff_data=diff(data);
diff_data=[0;diff_data];
diff_data=abs(diff_data);
</pre><pre class="language-matlab">[row,col]=find(diff_data>0);
</pre><p>kindly some one help, many thanks in advance,</p>Mekala balajihttps://jp.mathworks.com/matlabcentral/profile/authors/5786945-mekala-balajitag:jp.mathworks.com,2005:Question/1661392014-12-10T12:08:55Z2018-06-22T14:12:18Zcan't do parallel computing<p>Error using matlabpool (line 144)
Failed to open matlabpool. (For information in addition to the causing error, validate the profile 'local' in the Cluster Profile Manager.)</p><p>Error in feaExtract_parallel (line 28)
matlabpool local 12;</p><p>Error in run_vtln_all (line 2)
feaExtract_parallel( '../list/transform.list', 12);</p><p>Caused by:
Error using distcomp.interactiveclient/start (line 61)
Failed to locate and destroy old interactive jobs.
This is caused by:
The storage metadata file does not exist or is corrupt</p>yang Penghttps://jp.mathworks.com/matlabcentral/profile/authors/3245257-yang-pengtag:jp.mathworks.com,2005:Question/4069232018-06-22T09:48:20Z2018-06-22T14:10:04ZError writing and showing .txt in a standalone aplication <p>Hello everyone
I have a problem with an standalone application that creates a .txt file that writes and shows listings as a result, the file .m and .fig in matlab works perfectly, but when I try it in the executable the moment of displaying the .txt does not show anything and the program does not work, my original file in matlab uses this form:</p><pre> function CALCULATE_Callback(hObject, eventdata, handles)
global F;
global ValA;
global ValY;
global H;
global Interval;
syms x
syms y
ValY1= ValY;
n=abs((Interval-ValA)/H);
fid = fopen ('valuesA.txt', 'wt');
fprintf (fid, 'F (x, y) =% s \ n \ n', F);
fprintf (fid, 'x y \ n');
F= inline(F);
for i=1:n+1
y1 = feval(F,ValA,ValY1);
hy1=H*y1;
fprintf(fid,'\n%0.1f %0.7f \n', ValA, ValY1);
ValY1=ValY1+hy1;
ValA=ValA+H;
end
winopen('valuesA.txt')</pre><p>All the gui's and .m works perfectly in matlab, but not in the executable,
I'm using deploytool and attaching all the files my program uses (.m .fig .txt).
Thank you in advance.</p>DarioPachecohttps://jp.mathworks.com/matlabcentral/profile/authors/13032675-dariopachecotag:jp.mathworks.com,2005:Question/4069492018-06-22T13:26:09Z2018-06-22T14:09:45ZHow can I make below a certain value NaN so it does not effect my projection?<p>Hi, I am looking to project temperature on to a shapefile, I have a river that cuts through it and throws my colorbar off. Is there a command I can insert that says "any number less then 260 is NaN and should not be projected?"</p><p>Thank you!</p>Anna Vaculikhttps://jp.mathworks.com/matlabcentral/profile/authors/10516549-anna-vaculiktag:jp.mathworks.com,2005:Question/4068972018-06-22T06:17:25Z2018-06-22T13:57:24ZHow to save uitable & uifigure into pdf file?<p>I am generating a table and graph using uitable and uifigure function, and I need to save the uitable and uifigure into pdf file. However, the pdf file was successfully generated but it's blank. Is there anyway to do that?
My codes are as follow: <i>________________________________________________</i></p><p>fig = uifigure('Name','Numbers');
t = uitable(fig,'Data',[2,4,6,8;1,3,5,7]);
saveas(gcf,'Numbers','pdf')</p><p><i>________________________________________________</i></p>Tai Jia Xunhttps://jp.mathworks.com/matlabcentral/profile/authors/12655823-tai-jia-xuntag:jp.mathworks.com,2005:Question/4068282018-06-21T18:16:26Z2018-06-22T13:54:43ZSwing is not available in Mac High Sierra<p>I have recently purchased Arduino Engineering Kit and get an one year license to start using Matlab. I've followed the instruction to install Matlab on my Mac High Sierra.</p><p>First I could not start Matlab. I tried to start by command line still no luck.</p><p>Searched over the net, some suggested to start with -nojvm, this worked, however this also mean that I will stay in command line only as Matlab GUI all relies on Java AWT and Swing.</p><p>I decided to investigate more and realised that
I should specify MATLAB_JAVA to either</p><pre class="language-matlab">/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre
</pre><p>or</p><pre class="language-matlab">'/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home' (quote for the space).
</pre><p>Now I can start Matlab with Java enabled. However I still cannot start with GUI. Whenever I start Matlab without -nodisplay option, it crashes:</p><pre class="language-matlab">/Applications/MATLAB_R2018a.app/bin $ ./matlab
Abort trap: 6
/Applications/MATLAB_R2018a.app/bin $
</pre><p>Then I found some articles mentioned Matlab relies on X window as well. So I went to XQuartz and install the latest version, tried to start Matlab under xterm, no luck.</p><p>Another try to go to macports and install xorg-server and use X11 to start Matlab, still no luck.</p><p>Lastly when I start ./matlab -nodisplay and enable desktop, it said Swing is not available.</p><pre class="language-matlab">/Applications/MATLAB_R2018a.app/bin $ ./matlab -nodisplay
>> ver
---------------------------------------------------------------------------------------------------
MATLAB Version: 9.4.0.813654 (R2018a)
MATLAB License Number: Sponsored_Education
Operating System: Mac OS X Version: 10.13.5 Build: 17F77
Java Version: Java 10.0.1+10 with "Oracle Corporation" Java HotSpot(TM) 64-Bit Server VM mixed mode
---------------------------------------------------------------------------------------------------
MATLAB Version 9.4 (R2018a)
Simulink Version 9.1 (R2018a)
Control System Toolbox Version 10.4 (R2018a)
Curve Fitting Toolbox Version 3.5.7 (R2018a)
DSP System Toolbox Version 9.6 (R2018a)
Image Processing Toolbox Version 10.2 (R2018a)
Instrument Control Toolbox Version 3.13 (R2018a)
Optimization Toolbox Version 8.1 (R2018a)
Robotics System Toolbox Version 2.0 (R2018a)
Signal Processing Toolbox Version 8.0 (R2018a)
Simscape Version 4.4 (R2018a)
Simscape Multibody Version 5.2 (R2018a)
Stateflow Version 9.1 (R2018a)
Symbolic Math Toolbox Version 8.1 (R2018a)
</pre><pre class="language-matlab">>> desktop
Error using desktop (line 19)
desktop is not supported because:
Swing is not currently available.
</pre><pre class="language-matlab">>>
</pre><p>Anyone could share some thots to fix this? Thanks</p>Frankie Kanhttps://jp.mathworks.com/matlabcentral/profile/authors/13037749-frankie-kantag:jp.mathworks.com,2005:Question/4069522018-06-22T13:53:24Z2018-06-22T13:53:24ZIs there a way to avoid calling a superclass constructor during the execution of a subclass constructor?<p>When executing a superclass constructor, my code executes a subclass constructor. To avoid an infinite loop, I don't want the subclass constructor to execute the superclass constructor in this case. How do I avoid this? In particular, running the player class constructor prompts the user for selecting a file which determines which subclass to load the file as: Pfighter or Pwizard. The subclass, Pfighter, is a subclass of the player and character superclasses. This causes the player constructor to execute which causes an infinite loop due to the fact that the subclass can't pass information about the previous iteration to the superclass during instantiation. Again, not desirable. Can I retype the object to the lower class without rerunning the superclass constructor?</p><p>classdef character < handle</p><pre> % player class hierarchy
% handle
% |
% character
% |
% ------------------------------------------------
% | | | |
% AI wizard fighter player
%
% Cwizard (AI&wizard), Cfighter(AI&fighter), Pwizard (player&wizard), Pfighter(player&fighter)</pre><pre> properties
Name
Class
Level
Team
Marker
HP
MP
MPcost
Speed
Gun
Range
Damage
Spellbook
card
HPmax
status
ID
position
positionold
legend
scatter
outofbounds = false
levelup = false
AIplayer</pre><pre> % AI defined in CWizard, PWizard, CFighter, PFighter
% spells defined in wizard
% XP defined in PWizard, PFighter
% class defined in wizard and fighter
% MPcost defined in wizard
% Spellbook defined in wizard
% MPmax defined in wizard
end</pre><pre> methods</pre><pre> function obj = character(varargin) % obj = character(game,n)
% Help text
%
% player = player(game,n)
%
% game is a game object and n is a player number for the
% player ID
%
if nargin == 0
g = game('settings');
n = 1;
end</pre><pre> obj.status = status();
end</pre><pre> function obj = getcard(obj)
obj.card = card(obj.AIplayer);
fieldnames = fields(obj.card);
for j=1:size(fieldnames,1)
obj.(fieldnames{j}) = obj.card.(fieldnames{j});
end
if obj.AIplayer
if strcmp(obj.Class,'Fighter')
obj = Cfighter(obj);
else
obj = Cwizard(obj);
end
else
if strcmp(obj.Class,'Wizard')
obj = Pwizard(obj);
else
obj = Pfighter(obj);
end
end
%
% Set Starting Positions
%
s = settings;
switch obj.Team
case 'red'
obj.position = [-s.gridsize,-s.gridsize];
case 'green'
obj.position = [s.gridsize,s.gridsize];
case 'blue'
obj.position = [-s.gridsize,s.gridsize];
case 'yellow'
obj.position = [s.gridsize,s.gridsize];
end
if obj.AIplayer
obj.position = obj.position + [3*rand(),3*rand()];
end
obj.positionold = obj.position;
end
end
end</pre><p>classdef player < character</p><pre> % player class hierarchy
% handle
% |
% character
% |
% ------------------------------------------------
% | | | |
% AI wizard fighter player
%
% Cwizard (AI&wizard), Cfighter(AI&fighter), Pwizard (player&wizard), Pfighter(player&fighter)</pre><pre> properties
levels
XP
end</pre><pre> methods
function obj = player(obj)
% Add an XP-to-level table to the player structure to allow for checking
% level-up later in the game.
obj.AIplayer = false;
g = game('settings');
levelsfile = file([g.settings.LevelsPath g.settings.Levelfile],'int');
obj.levels = levelsfile.table;
if ~exist(obj.card)
obj.getcard;
end
obj.getXP;
end</pre><pre> function player = getXP(player)
if exist('XP.mat','file')
load('XP.mat')
else disp('No experience mat file found.');
return
end</pre><pre> XPexist = false;
for j = 1:size(experience,1)
if strcmp(experience{j,1},player.Name)
player.XP = experience{j,2};
XPexist = true;
end
if j==size(experience,1) && ~XPexist
player.XP = 0;
end
end
end
end
end</pre><p>classdef Pfighter < player & fighter</p><pre> % player class hierarchy
% handle
% |
% character
% |
% ------------------------------------------------
% | | | |
% AI wizard fighter player
%
% Cwizard (AI&wizard), Cfighter(AI&fighter), Pwizard (player&wizard), Pfighter(player&fighter)</pre><pre> properties</pre><pre> end</pre><pre> methods
function obj = Pfighter(obj)
obj.Class = 'Pfighter';</pre><pre> end
end</pre><p>end</p>Brett Spanglerhttps://jp.mathworks.com/matlabcentral/profile/authors/5365214-brett-spanglertag:jp.mathworks.com,2005:Question/4063372018-06-19T11:37:17Z2018-06-22T13:44:31Zmaking combinations from each leaf to parent node in Matlab<p>Hello, I have to make all combinations from a tree, starting from parent node and ends at the last leaf nodes.
The depth of all leaf nodes is same. I don't understand how can i get such a combination... starting from parent node ending to the leaf node.</p><p>Can anyone help please.</p>Sohaib Bin Altafhttps://jp.mathworks.com/matlabcentral/profile/authors/8352180-sohaib-bin-altaftag:jp.mathworks.com,2005:Question/4069182018-06-22T08:42:06Z2018-06-22T13:44:20ZHow can I modify the weights of a pre-trained Alexnet in 2018a?<p>Hi everybody. For a research project I need to modify the weights of a pre-trained Alexnet. When I try to do so:</p><pre class="language-matlab">net = alexnet;
net.Layers(2).Weights = net.Layers(2).Weights * 0.01;
</pre><p>Matlab 2017b answers me that they are read-only values. Since it looks a very strong limitation, does anybody know if in version 2018a they solved that problem? Or maybe someone has solve it with a script?</p><p>Thanks.</p>Valerio Gloriahttps://jp.mathworks.com/matlabcentral/profile/authors/7800652-valerio-gloriatag:jp.mathworks.com,2005:Question/3633792017-10-26T11:50:20Z2018-06-22T13:43:19ZMatlab App Designer axes component 'breaks' when computer goes on stand by<p>Hi all,</p><p>this is my first time creating an app so my knowledge of how it works is limited. I have created an app that takes some numerical inputs then when I click a button it uses these to plot a graph. I managed to get it working without too much hassle. However, twice now I have taken a break and when I come back to it the figures seem to be broken. It was working perfectly when I left it and when I came back to it I ran the code but nothing plots, although the legend still appears correctly. I haven't changed a thing in the code. Also when I look at the design view the title and y axis labels have disappeared (although they are still set in the configuration menu). The only way I can seem to fix this is to delete the axes component and insert a new one. It runs fine after that. Has anyone any ideas what is causing this?</p><p>Thanks
Carla</p>Carla Whitehttps://jp.mathworks.com/matlabcentral/profile/authors/5041869-carla-white