https://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2016-10-28T16:44:37Ztag:www.mathworks.com,2005:Question/3096662016-10-28T16:36:26Z2016-10-28T16:44:37ZHow to define constraints for lsqlin?<p>I was hoping you could help me solve a linear least-square problem. I am trying to use the <a href = "https://uk.mathworks.com/help/optim/ug/lsqlin.html?s_tid=gn_loc_drop">lsqlin function</a> to approximate the solution of a system of linear equations. I have defined a Matrix C and a vector d (so that the linear system is C*x = d). I also understand that lb and ub stipulate bounds on the solution (for the vector x). But I am struggling to understand what A, b, Aeq, and beq need to be specified as. Could you help me with this? Specifically, I am trying to solve for that C*x≥d).</p>Max Schweerhttps://www.mathworks.com/matlabcentral/profile/authors/5779170-max-schweertag:www.mathworks.com,2005:Question/3096672016-10-28T16:44:01Z2016-10-28T16:44:01ZPlotting vector using scatter cloud<p>I have a 100 3D vectors created using:</p><pre class="language-matlab">V = round(rand(100,3)*2-1);
</pre><p>I want to plot this vector in 3D using scatter3 (scatter cloud) but I need x y z values of the vector. How do I extract the x y z values. So the code I need to run is :</p><pre class="language-matlab">x = ...;
y = ...;
z = ...;
scatter3(x,y,z)
</pre><p>But I don't know how to get the x y z.</p>Jason Earlyhttps://www.mathworks.com/matlabcentral/profile/authors/7002978-jason-earlytag:www.mathworks.com,2005:Question/3051542016-09-30T03:20:36Z2016-10-28T16:43:39ZSeparating left and right leg data given ground reaction force gait data?<p>Hi,</p><p>I have an Excel file with several columns of ground reaction force data where each column is a different test subject. My question is, how can I separate each column into left leg data and right leg data. Where stride 1 is assumed to be the right leg, therefore all odd numbered strides are right leg strides and all even numbered strides are left leg strides. I have attached the first column of my data to give you an idea of what I am looking at. Any guidance would be great. Thank you so much!</p>Anthonyhttps://www.mathworks.com/matlabcentral/profile/authors/5103109-anthonytag:www.mathworks.com,2005:Question/3096542016-10-28T15:39:39Z2016-10-28T16:41:17ZStoring each realization as a variable<p>Hi,</p><p>I want to generate many realizations of different distributions and store each realization as a variable. For example, let's say I want to generate 100 different realizations of the function randn with mean=2 and std=5, where each realization has 10,000 points. How would I write the loop? So far I have:</p><p>x=cell(100,1);</p><p>for i:1=100</p><p>x{i}=5*randn(1,10000)+2;</p><p>y(i)=x{i};</p><p>end</p><p>I know this generates a cell. I would like to name each yi as each of the 100 realizations. Thanks!</p>Anthony Tamhttps://www.mathworks.com/matlabcentral/profile/authors/6905182-anthony-tamtag:www.mathworks.com,2005:Question/3094342016-10-27T09:20:22Z2016-10-28T16:36:26ZMatlab crashing when evaluating mex<p>I have the following C code, that I compile into a mex (32bit) with Visual Studio Express 2013:</p><pre class="language-matlab">#include <stdlib.h>
#include <stdio.h>
#include "mex.h"
</pre><pre class="language-matlab">void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
const size_t m = mxGetM(prhs[0]);
const size_t n = mxGetN(prhs[0]);
double** x = (double**)mxCalloc(n, m);
for (size_t i = 0; i < n; i++)
x[i] = (double*)mxCalloc(m, sizeof(double));
</pre><pre class="language-matlab"> for (size_t i = 0; i < n; i++)
mxFree(x[i]);
mxFree(x);
}
</pre><p>It is basically just allocating space to store a 2D matrix passed from Matlab, then deallocating it (without setting any value). When I compile it into mexw32 with Visual Studio Express 2013, then execute the following in Matlab 2013b 32bit, it crashes Matlab:</p><pre class="language-matlab">n = 51; x = zeros(3,n); myMex(x)
</pre><p>Here's the top of the stack log from the crash:</p><pre class="language-matlab">Stack: [0x00430000,0x00c30000], sp=0x00c23f7c, free space=8143k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [ntdll.dll+0x2e43e] RtlInitUnicodeString+0x196
C [ntdll.dll+0x2e0a3] RtlFreeHeap+0x7e
C [kernel32.dll+0x114bd] HeapFree+0x14
C [MSVCR100.dll+0x1016a] free+0x1c
</pre><p>Does anyone have any idea whatI'm doing wrong here? Is it down to the way I deallocate each pointer?</p><p>Thanks in advance for your answers.</p>MaFohttps://www.mathworks.com/matlabcentral/profile/authors/8810843-mafotag:www.mathworks.com,2005:Question/3096642016-10-28T16:12:09Z2016-10-28T16:35:45Z2nd ode RK4<p>Hi All,
I was requested to solve the following ode several weeks ago and suggested to use <b>Runge-Kutta</b> method.
One of my friends suggested me to expand the equation (in symbloic) to solve.
At the end of the day I could not do that by running through the elements by loop because some of the matries are samller. That will be very kind of you if you could help.
Thank you very much again!!!</p><pre class="language-matlab">x"=P(x)*[C(x)*P(x)]^-1*[D(x,x')-C(x)*Q(x,x',Tr(y),F_g(x,x'))]+Q(x,x',Tr(y),F_g(x,x'))
</pre><pre class="language-matlab">F= [C(x)*P(x)]^-1*[D(x,x')-C(x)*Q(x,x',Tr(y),F_g(x,x'))]
</pre><pre class="language-matlab">x is 14x1 matrix
P is 14x8 matrix
F is 8x1 matrix
Q is 14x1 matrix
Tr is 6x1 matrix
y is 12x1 matrix
F_g is 4x1 matrix
C is 8x14 matrix
D is 8x1 matrix
</pre><pre class="language-matlab">The following matrix also made me worry in the solving process
where y=h_f(x) --> y=1 when x>0 else y=0
y=f_f(x) --> y=max(0,x)
</pre><pre> where Tr is
Tr_1 = p_he*y(2)-p_hf*y(1);
Tr_2 = phe*y(4)-phf*y(3);
Tr_3 = pke*y(6)-pkf*y(5);
Tr_4 = pke*y(8)-pkf*y(7);
Tr_5 = (pae*y(10)-paf*y(9))*h_f(Fg_2);
Tr_6 = (pae*y(12)-paf*y(11))*h_f(Fg_4);</pre><pre> Where F_g
if y_r-y_g <0
Fg_1= -k_g*(x_r-x_r0) - b_g*(x_r_d);
Fg_2= -k_g*(y_r-y_r0) + b_g*f_f(-y_r_d);
else
Fg_1=0;
Fg_2=0;
end </pre><pre> if y_l-y_g <0
Fg_3= -k_g*(x_l-x_l0) - b_g*(x_l_d);
Fg_4= -k_g*(y_l-y_l0) + b_g*f_f(-y_l_d);
else
Fg_3=0;
Fg_4=0;
end</pre>revoxdynahttps://www.mathworks.com/matlabcentral/profile/authors/3213316-revoxdynatag:www.mathworks.com,2005:Question/3096552016-10-28T15:41:57Z2016-10-28T16:35:44ZError 354: No more machine transfers available. --- How long do I need to wait until I can again transfer the license?<p>I recently wanted to transfer a MATLAB license. I got the error "Error 354: No more machine transfers available". I wonder how long I have to wait until I can transfer the license again. Obviously, several people in this community have had the same problem. Does anybody know how long is the wait? Thanks!</p>Joerg Trogerhttps://www.mathworks.com/matlabcentral/profile/authors/3918551-joerg-trogertag:www.mathworks.com,2005:Question/3096652016-10-28T16:30:11Z2016-10-28T16:30:11ZHow to get coordinate at Kalman Filter for Object Tracking<p>Hi everyone,</p><p>I want to find the coordinate of the tracked object. The coordinate will be set to scale of the screen
what is the common of it.
Also, I have inserted the other video to the sample of configureKalmanFilter. And is it not accurate at the beginning. How to improve it?</p><p>Thank You</p><img src = "/matlabcentral/answers/uploaded_files/62185/%E6%9C%AA%E5%91%BD%E5%90%8D.jpg">Benny Leunghttps://www.mathworks.com/matlabcentral/profile/authors/8842540-benny-leungtag:www.mathworks.com,2005:Question/3096612016-10-28T15:58:35Z2016-10-28T16:30:06ZUsing dir to read in complex valued array.<p>Hello,</p><p>I'm trying to write a script general enough to read complex valued data from a varying number of .csv files. I've been using dir for this, but this seems to only pull in the real values from the file. Is there some way to get both the real and imaginary values with dir or should I be using a different function? Here is the code:</p><pre> fnames = dir(['Received_Signals\Gain\',gain_directory,'\*.csv']);
numfids = length(fnames);
vals = cell(1,numfids);
for k = 1:numfids
vals{k} = load(fnames(k).name);
end
for ig = 1: indep_gain_ct
if ig == 1
GHP_read = vals{1};
GHT_read = vals{2};
GVP_read = vals{3};
GVT_read = vals{4};
else
GHP_read = cat(3,GHP_read,vals{1+4*(ig-1)});
GHT_read = cat(3,GHT_read,vals{2+4*(ig-1)});
GVP_read = cat(3,GVP_read,vals{3+4*(ig-1)});
GVT_read = cat(3,GVT_read,vals{4+4*(ig-1)});
end % if ig
end % for ig</pre><p>Thanks.</p>Jeff Mhttps://www.mathworks.com/matlabcentral/profile/authors/7104123-jeff-mtag:www.mathworks.com,2005:Question/3096572016-10-28T15:42:15Z2016-10-28T16:22:00ZGenerating random 3D vectors<p>Hi,
I'm trying to create 100 random 3D vectors with entries [-1,1]. I'm new to matlab so it's very confusing to me at the moment.</p><p>I would very much appreciate your help.</p><p>Thank you.</p>Jason Earlyhttps://www.mathworks.com/matlabcentral/profile/authors/7002978-jason-earlytag:www.mathworks.com,2005:Question/3096532016-10-28T15:26:10Z2016-10-28T16:04:29Zhow to plot particular range of values from a function??in question i only want to plot those value of intensity whose range is 3.9 to 4..<pre class="language-matlab">x=[0:1*10^-8:1.38*10^-6];
y=x;
z=x;
[xx,yy,zz]=meshgrid(x,y,z);
lamda=0.532*10^-6;
y1 =exp((6.81*10^6.*xx+(6.81.*10^6.*yy)+(6.81.*10^6.*zz)).*1i);
y2=exp((2.27*10^6.*xx+(2.27.*10^6.*yy)+(11.36.*10^6.*zz)).*1i);
intensity=(y1+y2).*conj(y1+y2);
</pre>kamal ranahttps://www.mathworks.com/matlabcentral/profile/authors/9084352-kamal-ranatag:www.mathworks.com,2005:Question/3096622016-10-28T16:03:36Z2016-10-28T16:05:49ZArduino hardware support package installation location ?<p>Hi there,</p><p>I have downloaded and installed the arduino hardware package. However it is not appearing in my list of add-ons so eveytime I type:
a=arduino();</p><p>It states I need the arduino support package.</p><p>It has installed itself in a separate file called MATLAB,inside is R2015b then support packages, with this outside of my program files and program filesx86. My main MATLAB file is in the programx86 file.</p><p>Where can I move the support package file in order for this package to work?</p><p>Any help would be greatly appreciated.</p><p>Also this is some text that was printed while the package was installing.</p><p>Warning: Unable to save path to "C:\Program Files (x86)\MATLAB\R2015b\toolbox\local\pathdef.m".
MATLAB may not have write access to the folder. Possible fix:
1) Use SAVEPATH with an input argument to save path to a temporary file
2) Restart MATLAB as Administrator
3) Load path from temporary file
4) Call SAVEPATH
> In hwconnectinstaller.RegistryUtils.savePath
In hwconnectinstaller.PackageInstaller/install
In hwconnectinstaller.PackageInstaller/installRecursiveImp
In hwconnectinstaller.PackageInstaller/installRecursive
In hwconnectinstaller.internal.executeConfirm>installFromFolder
In hwconnectinstaller.internal.executeConfirm>installWorkflow
In hwconnectinstaller.internal.executeConfirm
In hwconnectinstaller.Step/next
In hwconnectinstaller.internal.executeConfirm>@(varargin)hStep.next(varargin{:})
In hwconnectinstaller.util.download.MWDownloadManager/fireMethod
In hwconnectinstaller.util.download.MWDownloadManager/initCallback/serviceCallback
In hgfeval (line 62)
In javaaddlistener>cbBridge (line 52)
In javaaddlistener>@(o,e)cbBridge(o,e,response) (line 47)
Warning: Unable to save path to "C:\Program Files (x86)\MATLAB\R2015b\toolbox\local\pathdef.m".
MATLAB may not have write access to the folder. Possible fix:
1) Use SAVEPATH with an input argument to save path to a temporary file
2) Restart MATLAB as Administrator
3) Load path from temporary file
4) Call SAVEPATH
> In hwconnectinstaller.RegistryUtils.savePath
In hwconnectinstaller.PackageInstaller/install
In hwconnectinstaller.PackageInstaller/installRecursiveImp
In hwconnectinstaller.PackageInstaller/installRecursive
In hwconnectinstaller.internal.executeConfirm>installFromFolder
In hwconnectinstaller.internal.executeConfirm>installWorkflow
In hwconnectinstaller.internal.executeConfirm
In hwconnectinstaller.Step/next
In hwconnectinstaller.internal.executeConfirm>@(varargin)hStep.next(varargin{:})
In hwconnectinstaller.util.download.MWDownloadManager/fireMethod
In hwconnectinstaller.util.download.MWDownloadManager/initCallback/serviceCallback
In hgfeval (line 62)
In javaaddlistener>cbBridge (line 52)
In javaaddlistener>@(o,e)cbBridge(o,e,response) (line 47)
Warning: Unable to save path to "C:\Program Files (x86)\MATLAB\R2015b\toolbox\local\pathdef.m".
MATLAB may not have write access to the folder. Possible fix:
1) Use SAVEPATH with an input argument to save path to a temporary file
2) Restart MATLAB as Administrator
3) Load path from temporary file
4) Call SAVEPATH
> In hwconnectinstaller.RegistryUtils.savePath
In hwconnectinstaller.PackageInstaller/install
In hwconnectinstaller.PackageInstaller/installRecursiveImp
In hwconnectinstaller.PackageInstaller/installRecursive
In hwconnectinstaller.internal.executeConfirm>installFromFolder
In hwconnectinstaller.internal.executeConfirm>performThreadedDownload
In hwconnectinstaller.internal.executeConfirm>installFromInternet
In hwconnectinstaller.internal.executeConfirm>installWorkflow
In hwconnectinstaller.internal.executeConfirm
In hwconnectinstaller.internal.executeConfirm
In hwconnectinstaller.Step/next
In hwconnectinstaller.internal.executeConfirm>@(varargin)hStep.next(varargin{:})
In hwconnectinstaller.util.download.MWDownloadManager/fireMethod
In hwconnectinstaller.util.download.MWDownloadManager/initCallback/serviceCallback
In hgfeval (line 62)
In javaaddlistener>cbBridge (line 52)
In javaaddlistener>@(o,e)cbBridge(o,e,response) (line 47)
Warning: Unable to save path to "C:\Program Files (x86)\MATLAB\R2015b\toolbox\local\pathdef.m".
MATLAB may not have write access to the folder. Possible fix:
1) Use SAVEPATH with an input argument to save path to a temporary file
2) Restart MATLAB as Administrator
3) Load path from temporary file
4) Call SAVEPATH
> In hwconnectinstaller.RegistryUtils.savePath
In hwconnectinstaller.PackageInstaller/install
In hwconnectinstaller.PackageInstaller/installRecursiveImp
In hwconnectinstaller.PackageInstaller/installRecursive
In hwconnectinstaller.internal.executeConfirm>installFromFolder
In hwconnectinstaller.internal.executeConfirm>performThreadedDownload
In hwconnectinstaller.internal.executeConfirm>installFromInternet
In hwconnectinstaller.internal.executeConfirm>installWorkflow
In hwconnectinstaller.internal.executeConfirm
In hwconnectinstaller.internal.executeConfirm
In hwconnectinstaller.Step/next
In hwconnectinstaller.internal.executeConfirm>@(varargin)hStep.next(varargin{:})
In hwconnectinstaller.util.download.MWDownloadManager/fireMethod
In hwconnectinstaller.util.download.MWDownloadManager/initCallback/serviceCallback
In hgfeval (line 62)
In javaaddlistener>cbBridge (line 52)
In javaaddlistener>@(o,e)cbBridge(o,e,response) (line 47)</p>Ruzamhttps://www.mathworks.com/matlabcentral/profile/authors/7424191-ruzamtag:www.mathworks.com,2005:Question/3096522016-10-28T15:25:54Z2016-10-28T16:03:01Z値の一般化<p>以下のプログラムで値を一般化しクラスに分類しプロットしたですが、一般化がうまくできていいないようなのですが何かアドバイス頂けると幸いです。</p><pre class="language-matlab">xfilename =('average.txt');
x = load(xfilename);
yfilename =('variarance.txt');
y = load(yfilename);
a=15;
rng default;
X = [x;y];
X = reshape(X,10368,2);
%NX = normc(X);
opts = statset('Display','final');
[idx,C] = kmeans(X,2,'Distance','cityblock','Replicates',5,'Options',opts);
plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12);
hold on;
plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12);
%plot(X(idx==3,1),X(idx==3,2),'g.','MarkerSize',12);
plot(C(:,1),C(:,2),'kx','MarkerSize',15,'LineWidth',3);
legend('Cluster 1','Cluster 2','Centroids','Location','NW');
title 'Cluster Assignments and Centroids';
hold off;
</pre>Naoki Ishibashihttps://www.mathworks.com/matlabcentral/profile/authors/8615671-naoki-ishibashitag:www.mathworks.com,2005:Question/3096502016-10-28T15:15:58Z2016-10-28T15:54:18ZThe images do not appear on the screen. What is wrong with the code?<p>I tried to run the whole program, but it got stuck after Line 145 (only the instruction slide, and the blank screen with fixation cross that appear on the screen). It won't get into the 'if loop' with the target images. When I tried to put some of the lines in 'if loop' just before the loop (before Line 151), the images appear on the screen. I am guessing it might be something wrong the way I wrote the condition matrix (Line 74 - 95?) and the way I call the condition in 'if loop' (Line 151 onwards). Can someone help me to figure out what is wrong with the code?</p><p>Thank you.</p><p>Regards,
Sabrina</p>nur sabrina subrihttps://www.mathworks.com/matlabcentral/profile/authors/6499498-nur-sabrina-subritag:www.mathworks.com,2005:Question/3096422016-10-28T14:08:01Z2016-10-28T15:54:00ZHow can I graph all the values of n in the while loop ? Theres my program.<pre> n=input('Enter a natural number');</pre><pre> cont=1:1:n;</pre><pre> while n>1</pre><pre> if rem(n,2)==0
n=n/2;</pre><pre> elseif rem(n,2)~=0
n=n*3+1;</pre><pre> end
plot(cont,n,'--rs');
end</pre>jonathan garciahttps://www.mathworks.com/matlabcentral/profile/authors/8879165-jonathan-garciatag:www.mathworks.com,2005:Question/3096592016-10-28T15:53:59Z2016-10-28T15:53:59ZCan i to use a opc-ua functions of Matlab into Simulink ¿?<p>Matlab contain a few of functions for a OPC-UA communications. How can i to use this functions into of Simulink ?
Thanks</p>Gran Canaritohttps://www.mathworks.com/matlabcentral/profile/authors/9084834-gran-canaritotag:www.mathworks.com,2005:Question/3096582016-10-28T15:52:45Z2016-10-28T16:16:53ZMatlab-Arduino Interfacing for PID temperature controller<p>Hello,</p><p>I have an arduino code for driving a peltier pile to a given set point (TEMP_SP). I am trying to input the set temperature from Matlab GUI (with different protocols, user will enter n temperatures and the time intervals, arduino will implement the PID controller and output the temperature to MATLAB every 1 seconds via serial communication.</p><p>I would appreciate any help.</p><p>My PID is working with arduino, I can send and receive data to/from matlab/arduino. I am using SerialEvent() to read the messages from matlab and print the responses accordingly.</p><p>The problem is that, (maybe because there is a huge delay between matlab and arduino), when I set a temperature from matlab, my peltier temperature jumps up and down crazily. E.g. I set 20 degrees celcius, my peltier jumps up to 35-40 degrees, then toggles around lower temperatures that are not super related to my set temperature. This does not happen when I run the PID on arduino and set the temperature directly from there.</p><p>PS: I am reading the temperature using a thermistor. I am changing the voltage using an external DAC and a shifter circuit because I need to both heat up and cool down ( the peltier terminals should change signs)</p><p>Algorithm:
-Set temperature (TEMP_SP)</p><p>-Read thermistor voltage-->convert to resistance-->convert to temperature (this is current state, T_C_CS)</p><p>-Find DAC output from PID</p><p>-SerialEvent() runs after every loop() to check if there's message coming from matlab and sets its flag accordingly.</p><p>-In each loop, check stringComplete flag and change the set temperature or print the current temperature.</p><p>This is my Arduino code:</p><pre> #include <Wire.h>
#include <Adafruit_MCP4725.h>
#include <PID_v1.h>
Adafruit_MCP4725 dac; // constructor</pre><pre class="language-matlab">uint32_t dac_value;
</pre><pre class="language-matlab">// Thermistor variables
float Rref=10000; //ohms, resistance of thermistor at 25C
float B25=3977;
float TOLB=0.75;
float A=-14.6337;
float B=4791.842;
float C=-115334;
float D=-3.730535E+06;
float A1t=3.354016E-03;
float B1t=2.569850E-04;
float C1t=2.620131E-06;
float D1t=6.383091E-08;
float Vdd=5; //volts
float R_divider=10000;//ohms
</pre><pre class="language-matlab">//CURRENT STATE
float Vt_CS_val; //current thermistor voltage value
float Vt_CS; //current thermistor voltage
float Rt_CS;//current thermistor resistance
float T_K_CS; //current temperature in K
float T_C_CS; //current temperature in C
float input_CS_val;// current input from the DAC
float input_CS;// current input from the DAC
</pre><pre class="language-matlab">//SET POINT
float TEMP_SP=20; //desired temperature (celcius)
float TEMP_SP_K; //desired temperature (Kelvin)
float R_SP; //desired resistance for the TEMP_SP_K
float Vt_SP; //desired thermistor voltage
</pre><pre class="language-matlab">//DAC output
float DAC_val;
float DAC_OUT;//DAC output voltage
//double PID_OUT;
</pre><pre class="language-matlab">//Custom PID
float der = 0;
float err;
float err_p;
float integral;
</pre><pre class="language-matlab">//PID set
float Kp=1.0, Ki=0.003, Kd=10.0;
float output;
int state=1;
</pre><pre class="language-matlab">float read_voltage;
float temp_rec;
float temp_new=20;
</pre><pre class="language-matlab">String inputString = ""; // a string to hold incoming data
</pre><pre class="language-matlab">String READ = "R";
boolean stringComplete = false; // whether the string is complete
</pre><pre class="language-matlab">void setup() {
Serial.begin(9600);
</pre><pre> dac.begin(0x62); // The I2C Address: Run the I2C Scanner if you're not sure
DAC_val=2080;//2.54V
dac.setVoltage(DAC_val, false); //819:1V, 3276:4V</pre><pre> // reserve 200 bytes for the inputString:
inputString.reserve(200);</pre><pre> Serial.println('a');
char a = 'b';
while(a != 'a')
{
a = Serial.read();
}
}</pre><pre class="language-matlab">void loop() {
</pre><pre> Vt_CS_val = analogRead(A1);
Vt_CS=5.0*Vt_CS_val/1024.0; //current voltage on thermistor, current temp
Rt_CS=R_divider*Vt_CS/(Vdd-Vt_CS);</pre><pre> //Given R, find T
T_K_CS=pow((A1t+B1t*log(Rt_CS/Rref)+C1t*pow((log(Rt_CS/Rref)),2)+D1t*pow((log(Rt_CS/Rref)),3)),-1); //KELVIN
T_C_CS=T_K_CS-273.15; //current Celcius</pre><pre> ///////PROCESS SET POINT</pre><pre> TEMP_SP_K=TEMP_SP+273.15; //Celcius to K
//Given T_SP, find R_SP
R_SP=Rref*exp(A+B/TEMP_SP_K+C/pow(TEMP_SP_K,2)+D/pow(TEMP_SP_K,3)); // R_SP</pre><pre> // find Vt_SP</pre><pre> Vt_SP=R_SP*Vdd/(R_SP+R_divider); //Set voltage for thermistor divider. Aim: Vt_SP=Vt_CS</pre><pre> err = Vt_SP - Vt_CS;
integral = integral + err;</pre><pre> output = Kp * err + (Ki * integral) + (Kd * der );
err_p = err;</pre><pre> DAC_OUT = -output + 2.5;</pre><pre> if (DAC_OUT< 1)
DAC_OUT = 1;
if (DAC_OUT > 4)
DAC_OUT = 4;</pre><pre> DAC_val=4096*DAC_OUT/5;</pre><pre> dac.setVoltage((int)DAC_val, false); </pre><pre> // print the answer when message arrives:</pre><pre> if (stringComplete) {</pre><pre> inputString.trim(); //remove newline characters or blanks</pre><pre> if( inputString==READ){</pre><pre> Serial.println(T_C_CS); //print the current temp</pre><pre> }
else //number came, take as temperature
{
temp_new=inputString.toFloat(); //set new temperature</pre><pre> TEMP_SP=temp_new;</pre><pre> Serial.println(TEMP_SP); //send the set temp back</pre><pre> }
inputString = "";
stringComplete = false;
}
}</pre><pre class="language-matlab">void serialEvent() {
</pre><pre> while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}</pre><p>Here is my matlab code:</p><pre class="language-matlab">%open serial object (working)
</pre><pre class="language-matlab">delete(instrfind({'Port'},{'COM11'}));%clear the port
%global ard;
if(~exist('serialFlag','var'))
[ard,serialFlag] = setupSerial('COM11');
end
disp('Connection successful');
</pre><pre class="language-matlab">isvalid=isvalid(ard);
</pre><pre class="language-matlab">%send set temperature (I am getting 28.00 back as TEMP_SP, so working)
x=28;
fprintf(ard,num2str(x));
msg=fscanf(ard);
disp(msg);
</pre><pre class="language-matlab">%read the temperature back every 3 seconds
while(1)
</pre><pre> fprintf(ard,'R');
msg=fscanf(ard);
disp(msg);
pause(3);
end</pre>Nil Gurelhttps://www.mathworks.com/matlabcentral/profile/authors/7109734-nil-gureltag:www.mathworks.com,2005:Question/3096492016-10-28T15:12:18Z2016-10-28T15:50:55ZHow to extract a subtable by rownames?<p>Hi,</p><p>I have a table of 10 columns and one column represent last names.
I would like to extract all the rows that belong to one last name.
How to do that?
Thanks in advance.</p><p>Jennifer</p>Jennifer Zhouhttps://www.mathworks.com/matlabcentral/profile/authors/6201072-jennifer-zhoutag:www.mathworks.com,2005:Question/3096562016-10-28T15:42:04Z2016-10-28T15:42:39ZParsing for String in Cell Array?<p>Hi everyone,
I have a large array of all diseases along with how often our clinic has seen them, but I'd like the user to choose a specific disease, let's say "sarcoma" and have just those diseases with umber of occurences to be saved.</p><p>Here's what I have:</p><pre class="language-matlab">prompt='Would you like to parse for a specific Diagnosis? (Y/N): ';
response=input(prompt,'s');
if strncmpi(response,'Y',1)==1
prompt='Which Diagnosis? ';
diagnosis=input(prompt,'s');
</pre><pre> potentials=Master(2:m,6);</pre><pre> [a c c]=unique(potentials);
d=hist(c,length(a));
f=cellstr(num2str(d(:)));</pre><pre> for i=1:length(a)
Z(i,1)=a(i,1);
Z(i,2)=f(i,1);
end</pre><pre> %for i=1:length(a)
%if a(i,1) contains diagnosis, add to C
%end</pre><pre> xlswrite(fullfile(path3,sprintf('Master %s.xls',datestr(now,'yyyymmdd'))),Z,'Sheet 3'); %Data of Sought Diagnosis
display ([diagnosis ' Data can be found on Sheet 3'])</pre><p>Master is a huge cell array that has patient data, the 6th column has their diagnoses; m is the number or rows in Master.</p><p>Any help would be appreciated!</p>Amul Choudharyhttps://www.mathworks.com/matlabcentral/profile/authors/9016899-amul-choudharytag:www.mathworks.com,2005:Question/3096432016-10-28T14:23:48Z2016-10-28T15:39:40ZWhy do I get an index error?<p>Here in this part of my code</p><pre class="language-matlab">r3 = randi([1 N],[G 1]);
for i = 1:G
ch = ceil(r3(i,1)/3840);
[r, c] = ind2sub([4 960],r3-((ch-1)*3840));
if Ma{ch,1}(r,c) == 0
Ma{ch,1}(r,c) = 1;
else
Ma{ch,1}(r,c) = 0;
end
end
</pre><p>'r' and 'c' can't be zero, but I get:</p><pre class="language-matlab">??? Subscript indices must either be real positive integers or
logicals
</pre><p>Would you please help me with this?</p>Sherwinhttps://www.mathworks.com/matlabcentral/profile/authors/8854002-sherwintag:www.mathworks.com,2005:Question/792812013-06-17T11:41:58Z2016-10-28T15:38:38ZCreate a structure name based on the string of a variable. Create fieldnames in this structure.<p>Inside a function I have a variable called name which is a char class. I want to generate a structure based on the string of variable *name *and then create fields in this structure.</p><pre class="language-matlab">name =
</pre><pre class="language-matlab">report 1
</pre><p>I do the following to create a variable with the string of variable name.</p><pre class="language-matlab">v=genvarname(strrep(name, ' ', '_'));
</pre><p>Then in my function I have created other variables which have certain values. I want to create fieldnames in the previous structure with the name of these variables. Those fieldnames will have the same value as the corresponding value of the variable.</p><p>example:</p><pre class="language-matlab">a=mean([1 2 3 4]);
b=std([1 2 3 4]);
</pre><p>What I want to create is the following:</p><pre class="language-matlab">report_1.a= 2.5000
report_1.b=1.2910
</pre><p>My final goal is to create an output in the function with structure report_1.</p>Giorgos Papakonstantinouhttps://www.mathworks.com/matlabcentral/profile/authors/3060153-giorgos-papakonstantinoutag:www.mathworks.com,2005:Question/3095482016-10-27T21:53:58Z2016-10-28T15:36:18ZHelp Solving an Equation<p>Hi,</p><p>I am trying to solve the following function for x where er, Re and d_i are known values:</p><p>x+4*log10(er/(3.7*d_i)+1.4125*x/Re)=0</p><p>I have tried several methods and cant seem to get the right answer. I know that the correct answer is approximately 10.8. Can anyone help me set this up?</p><p>Thanks in advance</p>Brittany Caughronhttps://www.mathworks.com/matlabcentral/profile/authors/7560779-brittany-caughrontag:www.mathworks.com,2005:Question/3084162016-10-21T10:15:28Z2016-10-28T15:35:38ZCreation of Simulink Real-Time CD Boot image failed. Matlab r2016b, Win 10.<p>Hello everyone,</p><p>Using the Simulink Real-Time Explorer (slrtexplr, former xpcexplr) I cannot create a bootable disk.\
I get the error:
"Creation of Simulink Real-Time CD Boot image failed."</p><p>Using the command line commands xpcbootdisk or SimulinkRealTime.createBootImage
give both the same error:
">> xpcbootdisk
Current boot mode: CDBoot
Creation of Simulink Real-Time CD Boot image failed."
">> SimulinkRealTime.createBootImage
Current boot mode: CDBoot
Creation of Simulink Real-Time CD Boot image failed."</p><p>When googling the problem I found the following old Thread having a similar but different problem (https://ch.mathworks.com/matlabcentral/newsreader/view_thread/323331).
In my case the CDboot.iso does not exist on my harddrive, also not in the temporary directory located with "tempdir".</p><p>I am using a Windows 10 64bit (Edu) version and Matlab r2016b.
Since it already fails at creating an iso image, I do not think that hardware/driver information for the CD/DVD burner is relevant. Please let me know if I am mistaken.</p><p>I have now tested the same on a Windows 7 pro 64 bit machine and I receive the same failure to create the image.
This seems to be a bug and therefore I create a bug report.</p><p>Thanks for your help/support,</p><p>best regards
Nicolas Gerig</p>Nicolashttps://www.mathworks.com/matlabcentral/profile/authors/3152164-nicolastag:www.mathworks.com,2005:Question/3077182016-10-17T17:38:19Z2016-10-28T15:31:55ZHow to make level curves if function is unknown?<p>I need to draw a level curve. I had data for x-axis, y-axis and z-axis through which I can draw 3D plot. However, f(x,y) is unknown. How can create the level curves for my data?</p>shailender gautamhttps://www.mathworks.com/matlabcentral/profile/authors/8875296-shailender-gautamtag:www.mathworks.com,2005:Question/3096462016-10-28T14:32:09Z2016-10-28T15:31:07ZHow to get the p-value as an output of fitlm?<p>Hi,</p><p>I'm trying to isolate the p-value from the output of the fitlm function, to put into a table. I have 180 regressions to get the p-value for, so manually copying and pasting isn't practical.</p><p>I have managed to do this for the R-squared value using the following:</p><pre class="language-matlab">mdl = fitlm(x,y);
p_val = mdl.squared.Ordinary;
</pre><p>Does anyone know how to do the same for the p-value?</p><p>Thanks!</p>Casey Jemima Shepheardhttps://www.mathworks.com/matlabcentral/profile/authors/8835211-casey-jemima-shepheardtag:www.mathworks.com,2005:Question/3096482016-10-28T15:03:50Z2016-10-28T15:24:55ZHow can I calculate the energy of an audio file (audio signal) that I imported in Matlab? <p>Im trying to calculate the energy of an audio file in matlab. I wnat to calculate its energy before and after filtering. Here's my matlab script:
clear('all');</p><p>close('all');</p><p>[f,fs] = audioread('test.wav');</p><p>N = size(f,1); % Determine total number of samples in audio file</p><p>figure;</p><p>subplot(2,1,1);</p><p>plot(1:N, f(:,1));</p><p>title('Left Channel');</p><p>subplot(2,1,2);</p><p>plot(1:N, f(:,1));
title('Right Channel');</p><p>n = 2;</p><p>fprintf('The sum of the absoulte values (Before filtering) is: \n');</p><p>fff = fft(f);</p><p>h = sum(abs(fff));</p><p>max(f)</p><p>disp(h)</p><p>beginFreq = 700 / (fs/2);</p><p>endFreq = 1600 / (fs/2);</p><p>[b,a] = butter(n, [beginFreq, endFreq], 'bandpass');</p><p>fOut = filter(b, a, f);</p><p>% Construct audioplayer object and play</p><p>%p = audioplayer(fOut, fs);</p><p>%p.play;</p><p>fprintf('The sum of the absoulte values (After filtering) is: \n');</p><p>figure;</p><p>plot(filter(b, a, f))</p><p>ggg = fft(f);</p><p>h = sum(abs(ggg));</p><p>disp(h)</p><p>fprintf('Sampling Frequency is: \n');</p><p>disp(fs)</p>Aziz Alharbihttps://www.mathworks.com/matlabcentral/profile/authors/8978817-aziz-alharbitag:www.mathworks.com,2005:Question/3096512016-10-28T15:23:06Z2016-10-28T15:23:06Zlsqnonlin: failure in initial user-supplied function<p>Dear MATLAB users, I have some troubles with lsqnonlin.
I either obtain an error saying:
<i>Failure in initial user-supplied objective function evaluation. LSQNONLIN cannot continue.</i>
if I use the function as provided below, or obtain an error saying: <i>User-defined Jacobian is not the correct size: the Jacobian matrix should be 3-by-3.</i>
if I define the Jacobian as</p><pre class="language-matlab">J = [-TE.*x(2).*e; e+delta; delta];
</pre><p>But I disagree with this because I have only one function with three variables, hence the jacobian should be 1 by 3...</p><p>Any idea to help me would be greatly appreciated!
Thank you!</p><p>My function:</p><pre class="language-matlab">function map = r2PixelFitNonLinDelta(M, TE)
M = squeeze(M);
if(size(TE,1) == 1)
TE = TE';
end
options = optimset('Display','off','MaxIter',100,'TolFun',1e-6,'Jacobian','on');
R2 = 0.08;
M0 = 1;
delta0 = 0.09;
x0 = [R2;M0;delta0];
map = zeros(size(M,1),size(M,2),numel(x0));
for y = 1:size(M,1);
parfor x = 1:size(M,2);
dat = reshape(M(y,x,:),[numel(TE) 1]);
map(y,x,:) = lsqnonlin(@(x)fun(x, TE, dat), x0 , [] , [], options);
end
end
end
</pre><pre class="language-matlab">function [F J] = fun(x, TE, M)
delta = x(3);
e = exp(-TE.*x(1));
F = x(2).*(e + delta) - M;
J = [-TE.*x(2).*e, e+delta, delta];
end
</pre>Emilie Mussardhttps://www.mathworks.com/matlabcentral/profile/authors/3849284-emilie-mussardtag:www.mathworks.com,2005:Question/3081752016-10-20T02:54:18Z2016-10-28T15:21:32Zhow can i build a tic tae toe game in matlab<p>am confused on how building a matlab code for this game</p>omar hamidhttps://www.mathworks.com/matlabcentral/profile/authors/8596457-omar-hamidtag:www.mathworks.com,2005:Question/3096282016-10-28T11:21:05Z2016-10-28T15:15:54Znon linear equations systems <p>Hi
I would like to know if this can be solved analytically using MATLAB. Let x, y and z are variables and</p><pre class="language-matlab">if true
e^x=z
e^y=x
e^z=x
</pre><pre class="language-matlab">end
</pre>Flight86https://www.mathworks.com/matlabcentral/profile/authors/7259750-flight86tag:www.mathworks.com,2005:Question/837282013-08-01T07:54:44Z2016-10-28T15:08:26ZHow to extract and recognise the vechile plate number with matlab?<p>I want to develop an matlab program that can extract and recognise the plat number of vechile with templete mactching method. Here is my code..</p><pre> function letters = PengenalanPlatMobil(citra)
%load NewTemplates
%global NewTemplates
citra=imresize(citra,[400 NaN]); % Resizing the image keeping aspect
ratio same.
citra_bw=rgb2gray(citra); % Converting the RGB (color) image to gray
(intensity).
citra_filt=medfilt2(citra_bw,[3 3]); % Median filtering to remove
noise.
se=strel('disk',1);
citra_dilasi=imdilate(citra_filt,se); % Dilating the gray image with
the structural element.
citra_eroding=imerode(citra_filt,se); % Eroding the gray image with
structural
element.
citra_edge_enhacement=imsubtract(citra_dilasi,citra_eroding);
%Morphological
Gradient for edges enhancement.
imshow(citra_edge_enhacement);
citra_edge_enhacement_double=mat2gray(double(citra_edge_enhacement)); %
Converting the class to double.
citra_double_konv=conv2(citra_edge_enhacement_double,[1 1;1 1]);
%Convolution
of the double image f
citra_intens=imadjust(citra_double_konv,[0.5 0.7],[0 1],0.1);
%Intensity
scaling between the range 0 to 1.
citra_logic=logical(citra_intens); % Conversion of the class from double
to binary.
% Eliminating the possible horizontal lines from the output image of
regiongrow
% that could be edges of license plate.
citra_line_delete=imsubtract(citra_logic,
(imerode(citra_logic,strel('line',50,0))));
% Filling all the regions of the image.
citra_fill=imfill(citra_line_delete,'holes');
% Thinning the image to ensure character isolation.
citra_thinning_eroding=imerode((bwmorph(citra_fill,'thin',1)),
(strel('line',3,90)));</pre><pre> %Selecting all the regions that are of pixel area more than 100.
citra_final=bwareaopen(citra_thinning_eroding,125);
[labelled jml] = bwlabel(citra_final);
% Uncomment to make compitable with the previous versions of MATLAB®
% Two properties 'BoundingBox' and binary 'Image' corresponding to these
% Bounding boxes are acquired.
Iprops=regionprops(labelled,'BoundingBox','Image');</pre><pre> %%% OCR STEP
[letter{1:jml}]=deal([]);
[gambar{1:jml}]=deal([]);
for ii=1:jml
gambar= Iprops(ii).Image;
letter{ii}=readLetter(gambar);
% imshow(gambar);
%
end
%%</pre><pre> end
end</pre>farhathttps://www.mathworks.com/matlabcentral/profile/authors/4364745-farhattag:www.mathworks.com,2005:Question/3095552016-10-27T23:03:20Z2016-10-28T15:06:20ZRadius of droplet over time<p>I want to measure the radius of a droplet over time. My droplet contains cells and Im not able to have accurate values of radius the droplet. Can someone suggest something? Thanks</p><img src = "/matlabcentral/answers/uploaded_files/62142/Yeast%20cells%20in%20a%20droplet.jpg">Piyush Katakwarhttps://www.mathworks.com/matlabcentral/profile/authors/7168264-piyush-katakwartag:www.mathworks.com,2005:Question/3081652016-10-20T00:29:58Z2016-10-28T14:59:38ZWhat should be the dimension of the 'X' matrix when fitting a ARIMAX(p,q) model?<p>I'm Fitting an ARIMAX(p,q) model to a time series data with one exogenous variable.
What should be the length of the 'X' matrix that I need to specify?</p><p>Thanks!</p>Ali Fathi Baghbadoranihttps://www.mathworks.com/matlabcentral/profile/authors/7995822-ali-fathi-baghbadoranitag:www.mathworks.com,2005:Question/3093422016-10-26T19:39:35Z2016-10-28T14:54:45Zpulseperiod function problem with statelevels<p>Hi everyone,
I am currently using Matlab 2016a to compute heart period from a ppg pulse waveform. I already and successfully used the pulseperiod function to compute the respiratory frequency but on my ppg waveform the upper and lower states (and as a consequence the mid-level threshold) are set too high (due to many artifacts) by the pulseperiod function. I wanted to lower this threshold and set the upper and lower states at 0.05 and - 0.05 v respectively. I already tried using the syntax P = pulseperiod(X, T, 'StateLevels', [-0.05 0.05]) but this does not seem to change anything.
with X = my ppg variable and T = my time variable.
Is there a problem in my syntax ? If yes, what would be the correct syntax to set a user-defined threshold (mid-level) or State Levels ? I am sorry but I am new to Matlab.
Thank you in advance,
Best regards</p>Jérémy Dos Santoshttps://www.mathworks.com/matlabcentral/profile/authors/8969137-jeremy-dos-santostag:www.mathworks.com,2005:Question/3096472016-10-28T14:53:57Z2016-10-28T14:53:57Zusing deploytool when the function uses a static/classdef function<p>I had a simple optimization problem for test.
I used Yalmip to build this test problem like this</p><pre class="language-matlab">function a=test(lowerlimit,upperlimit)
x=sdpvar(1,1);%sdpvar is a Yalmip function to define decision variables
H=5*x^2-17*x+10;%this is the objective function
F=(lowerlimit<=x<=upperlimit);%this is the constraint
tic
aaa=solvesdp(F,H,sdpsettings('solver','GUROBI'));%I solve this problem with Gurobi, solvesdp is a Yalmip function
toc
a=double(x)
</pre><pre class="language-matlab">end
</pre><p>This function works well in Matlab R2012a, and I used deploytool to package this function to a java class, it succeeded.
However, when I run this java class in IDEbeans, here comes the error:</p><ul><li>Undefined function 'yalmip' for input arguments of type 'char'.</li><li>Error in sdpvar (line 508)</li><li>Error in test (line 2)</li><li>Exception: com.mathworks.toolbox.javabuilder.MWException: Undefined function 'yalmip' for input arguments of type 'char'.</li></ul><p>After seaching for this through the internet, I can almost make sure that this is due to the fact that the Yalmip function sdpvar is located in a class folder</p><img src = "/matlabcentral/answers/uploaded_files/62179/QQ%E6%88%AA%E5%9B%BE20161028225150.jpg"><p>However I am not very sure how to solve this.
I also find some similar questions like this <a href = "http://cn.mathworks.com/matlabcentral/answers/165412-using-deploytool-with-classdef-and-private-functions">http://cn.mathworks.com/matlabcentral/answers/165412-using-deploytool-with-classdef-and-private-functions</a></p><p>Could anyone help me out ?</p><p>Thanks you guys very much!</p>Dailhttps://www.mathworks.com/matlabcentral/profile/authors/4098440-dailtag:www.mathworks.com,2005:Question/3088712016-10-24T14:24:08Z2016-10-28T14:52:49ZCUDA 8 supported in R2016b?<p>Any chance that a new version of Parallel Computing Toolbox with latest CUDA 8 toolkit will be released before R2017a, so in current release R2016b?</p>Bert RAM Aertshttps://www.mathworks.com/matlabcentral/profile/authors/4146954-bert-ram-aertstag:www.mathworks.com,2005:Question/1381642014-06-28T19:35:03Z2016-10-28T14:43:35ZWhy is spectrum.periodogram not recommended, and how to substitute pwelch in it's place?<p>A message pops up in Matlab when I use spectrum.periodogram to find the median frequency of a signal, saying that it is not recommended. Why is this? I also get the same message for spectrum.pwelch</p><p>I am implementing the solution described by <a href = "http://www.mathworks.com/matlabcentral/answers/34879-median-frequency-fmed">Median Frequency using spectrum.periodogram</a>
which is:</p><pre class="language-matlab">psdest = psd(spectrum.periodogram,x,'Fs',1000,'NFFT',length(x));
normcumsumpsd = cumsum(psdest.Data)./sum(psdest.Data);
Ind = find(normcumsumpsd <=0.5,1,'last');
fprintf('Median frequency is %2.3f Hz\n',psdest.Frequencies(Ind));
</pre><p>After lots of research I still don't understand the output of the psd well enough so that I can susbstitute spectrum.periodgram. Normally I find my PSD using:</p><pre class="language-matlab">[Pxx,Fx] = pwelch(s,[],[],[],fs);
plot(Fx,10*log10(Pxx))
</pre><p>Ideally I would like to find the median frequency by manipulating the Pxx and Fx values but I am struggling to relate Pxx directly to psdest.Data. I would be grateful if someone could point me in the right direction. Thank you in advance!</p>Maryhttps://www.mathworks.com/matlabcentral/profile/authors/5231410-marytag:www.mathworks.com,2005:Question/348792012-04-09T00:48:19Z2016-10-28T14:41:07ZMedian Frequency(Fmed)<p>I need help finding the Median frequency of a power spectram. (Fmed), I am new to matlab so any helo will be really appreciated.</p>shez96https://www.mathworks.com/matlabcentral/profile/authors/2830694-shez96tag:www.mathworks.com,2005:Question/3096212016-10-28T10:17:35Z2016-10-28T14:37:34ZSystem of differential equations with constant (as variables) coefficients<p>Hi</p><p>I have 4 differential equations that I need to solve, but the coefficients for each term in each equation are different unknown constants. I read about solving it using a matrix and came up with:</p><pre class="language-matlab">syms A(t) B(t) C(t) D(t) k1 kn1 k2 kn2 k3 kn3 k4 kn4 k5 kn5 k6 kn6
</pre><pre class="language-matlab">Z = [A;B;C;D];
X = [-(k1+k3+k5), kn1, kn3, kn5; k1, -(kn1+k2+k6), kn6, kn2; k3, k6, -(kn3+k4+kn6), kn4; k5, k2, k4, -(kn2+kn4+kn5)];
</pre><pre class="language-matlab">Y = zeros(4,1);
</pre><pre class="language-matlab">eqn = diff(Z) == X*Z + Y;
</pre><pre class="language-matlab">[ASol(t), BSol(t), CSol(t), DSol(t),] = dsolve(eqn);
</pre><p>however that does not seem to work. Any help would be appreciated</p>Marc Rosaleshttps://www.mathworks.com/matlabcentral/profile/authors/9082957-marc-rosalestag:www.mathworks.com,2005:Question/3095982016-10-28T07:45:01Z2016-10-28T14:35:15ZIs it possible getting x coördinates from an accelerometer measurement?<p>Hello,
I have a dataset from a measurement with an accelerometer.
The figure below displays the resultant vector of the X, Y and Z axis.</p><img src = "/matlabcentral/answers/uploaded_files/62162/Knipsel.PNG"><p>I would like to know if it is possible getting the x coördinates (Time in seconds) from the beginning when the signal starts getting bigger until the moment it gets back to normal. So this means the first x coördinate would be around 270 sec en the second 570 sec and so on until the end of the signal.</p><p>Until now I have done it visually because I have had only two test subjects. But it would be of great help if there is some way to do this automatically.</p>Shawn Imminghttps://www.mathworks.com/matlabcentral/profile/authors/6887268-shawn-immingtag:www.mathworks.com,2005:Question/3083902016-10-21T07:58:05Z2016-10-28T14:16:27Zreturn mwArray from cpp mex function<p>Hi, i think this is quite a simple problem, but anyway, i could not find quickly via documentation or google.
I have C++ code where a mwArray of mxSTRUCT_CLASS is set up.</p><p>I need to find a way to get that mwArray into the Matlab Workspace now or maybe a way to convert that into a mxArray to get it into the Matlab Workspace.</p><p>That's all ... i guess a hint where to find that in the documentation would be a very helpful one.</p><p>Anyway, thanks for your interest and kind regards,</p><p>Ulrich</p>Ulrichhttps://www.mathworks.com/matlabcentral/profile/authors/4857444-ulrichtag:www.mathworks.com,2005:Question/3096042016-10-28T08:46:11Z2016-10-28T14:07:38ZI'm trying to print a figure to PS on 2015a 64bit the function was working perfectly on 2012b 32bit but now the function is really slow<p>the command is really simple:
print(figure_handles, '-dpsc2','-append',PSFileName, '-r400');</p>Omar Abdelkaderhttps://www.mathworks.com/matlabcentral/profile/authors/8894405-omar-abdelkadertag:www.mathworks.com,2005:Question/2339282015-08-14T19:16:49Z2016-10-28T14:04:20ZMATLAB 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://www.mathworks.com/matlabcentral/profile/authors/434782-walter-robersontag:www.mathworks.com,2005:Question/3087962016-10-24T06:12:41Z2016-10-28T14:01:26ZPlot gridbox and point<p>Hi all,
I have two datasets</p><ol><li>Simulated temperature</li><li>Observed temperature</li></ol><p>Simulated data is given by gridboxes: for example the temperature in the coordinate (longitude = 0, latitude=0) is the simulated temperature in the gridbox 0 degrees to 1.25degrees longitude, and 0 degrees to 0.47 latitude.
The observed temperature can be the coordinate (lon=0.52, lat=0.33), thus included in the gridbox for simulated data.</p><p>I want to plot the gridbox <i>around</i> the observed coordinate.
That is: the box I want to plot for simulated data should start in (0,0) in the lower left corner.
I tried the plot:</p><p>scatter(lonsimul, latsimul,'s')
hold on
scatter(lonobs, latobs,'.')</p><p>but it seems the first plot has the simulated coordinate, (0,0), as the center, and not the lower left corner.</p><p>Is there any way to do this?</p><p>Thomas</p>Thomas Leirvikhttps://www.mathworks.com/matlabcentral/profile/authors/6591725-thomas-leirviktag:www.mathworks.com,2005:Question/3095612016-10-28T00:27:55Z2016-10-28T14:00:50ZWhy do I get subscript indices error?<p>Hi, I have a code like this,</p><pre> r2 = randi([2 64]);
[m, n] = ind2sub([4 16],r2);
n = (n-1)*60;
CH1(m:end,n:end) = P2(m:end,n:end);</pre><p>CH1 and P2 are two matrices. I generated 'r2' randomly and used 'ind2sub' to find the indices of the element r2. So I expected m and n to be numbers, but I get this error:</p><pre class="language-matlab">??? Subscript indices must either be real positive integers or
logicals.
</pre><p>Please help.</p>Sherwinhttps://www.mathworks.com/matlabcentral/profile/authors/8854002-sherwintag:www.mathworks.com,2005:Question/3096112016-10-28T09:25:14Z2016-10-28T14:13:12ZRemove elements from a structure array, whose values also exist in a different structure array<p>Hi all. Question from novice: I have 2 structure arrays and I would like to remove all elements from one array, which have a name, that also exist as the same name in the other structure array. My code so far:</p><pre class="language-matlab">file_plots = dir('*.jpg');
file_raw = dir('*.csv');
</pre><pre class="language-matlab">% remove file extensions
for i = 1:1:length(file_raw)
file_total_raw(i).name = file_raw(i).name(1:length(file_raw(i).name)-4);
end;
</pre><pre class="language-matlab">for i = 1:1:length(file_plots)
file_existing_plots(i).name=file_plots(i).name(1:length(file_plots(i).name)-4);
end;
</pre><p>Some more info:</p><pre class="language-matlab">file_plots =
</pre><pre class="language-matlab">6x1 struct array with fields:
</pre><pre> name
date
bytes
isdir
datenum</pre><pre class="language-matlab">file_raw =
</pre><pre class="language-matlab">11x1 struct array with fields:
</pre><pre> name
date
bytes
isdir
datenum</pre><p>Specifically: I want to filter out all elements of file_raw, which share a name with file_plots and the results should also be a new structure array called file_raw_filtered. Hope this describes my problem and many many thanks!
Max</p>Max Lehhttps://www.mathworks.com/matlabcentral/profile/authors/9083033-max-lehtag:www.mathworks.com,2005:Question/3095932016-10-28T06:36:26Z2016-10-28T13:58:40ZLogical condition for a while lopp exits prematureley<p>Hi,
I have this while loop criteria,</p><pre class="language-matlab">while((std(PenPar(:,2),0,1) > 50 && std(PenPar(:,3),0,1) > 50 && std(PenPar(:,4),0,1) > 50) || Stopper==500)
</pre><p>but it stops prematurely; only one of the and terms are satisfied.</p><p>Can someone explain me why it is so?
Best reagrds</p>Philip Berghttps://www.mathworks.com/matlabcentral/profile/authors/8432593-philip-bergtag:www.mathworks.com,2005:Question/3096412016-10-28T04:00:00Z2016-10-28T13:58:01ZHow do I view my installed support packages?<p>How can I view all support packages that I have installed into my MATLAB installation?</p>MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/3091162016-10-25T16:28:15Z2016-10-28T13:57:59ZThe iradon transform of coherent data does not work. Why?<p>The iradon transform of coherent data does not work. Why?</p>Ioannis Vagiashttps://www.mathworks.com/matlabcentral/profile/authors/4854969-ioannis-vagiastag:www.mathworks.com,2005:Question/3064682016-10-09T09:47:30Z2016-10-28T13:57:13ZOut of Memory error!<p>I am scanning from azimuth 1 to 45 by using 20by20 URA narrowband tx array block. The input port 'W' is being fed by a function block which is coded as follows :</p><pre class="language-matlab">function y = SIGNAL_STEER(signal)
coder.extrinsic('phased.URA', 'steervec', 'getElementPosition');
y=zeros(400,45);
az=45;
fc=36e9;
v=3e8;
lambda=v/fc;
ss=phased.URA('Size',[20 20],'ElementSpacing' , lambda/2);
elem_pos=(getElementPosition(ss)/lambda);
for le=1:1:az;
sv=steervec(elem_pos,le);
complex_arr=conj(sv);
% y=zeros(size(sv));
y=complex_arr;
end
end
</pre><p>My signal is of 50000by1 dimension, output 'y'is 400by1 and it must be a column vector. When this signal is reflected back from the target and fed into Rx narrowband array block having same configuration as of Narrowband tx array block I get output dimension of 50000by400 which I believe is correct as my URA is 20by20.
I believe that my dimensions are correct but I am getting out of memory error! How to resolve it</p>Hassam Mahmoodhttps://www.mathworks.com/matlabcentral/profile/authors/4301207-hassam-mahmoodtag:www.mathworks.com,2005:Question/3096402016-10-28T13:57:01Z2016-10-28T13:57:01ZImplement Transfer Function of motor in C<p>Hello, I'm trying to model a motor. I was given a Transfer Function of a motor that is in the S-Domain and need to implement it in C. I believe I need to do an inverse Laplace transform to get it into the continuous time domain. Now I'm thinking because it will be running in C and I'm taking discrete samples of the input voltage then I should convert the continuous time domain to the discrete time domain. From there I should be able to convert it to C language. I have to admit that I have not used Laplace Transforms in 20 years. Can anyone give me some help?</p><p>Thanks,
joe</p>Josephhttps://www.mathworks.com/matlabcentral/profile/authors/219982-joseph