http://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2016-08-28T20:34:21Ztag:nl.mathworks.com,2005:Question/3007972016-08-24T21:06:47Z2016-08-28T20:34:21ZWhy does MATLAB crash when I make a function call on C code or DLL in MATLAB (R2016a)?<p>I am using matlab R20016a, I made mex file for c function successfully. But the matlab has crush after debugging the code with corrupted data. However the c functions builts on 2000 and 2001.</p>Ahmedhttp://nl.mathworks.com/matlabcentral/profile/authors/4777229-ahmedtag:nl.mathworks.com,2005:Question/3011792016-08-28T20:18:29Z2016-08-28T20:31:30ZResampling a vector to change its length<p>Hi all,</p><p>I have a series of vectors that all have different lengths (100<length<150), and I want to standardise their length to 100 frames so that I can put them into a matrix and perform PCA on it. I have tried using the resample function to reduce the length of my vectors one by one, but I am having issues with the ripples at the beginning and end of my resampled vectors. For example, let's say I have a vector x with 111 values. What I wrote is:</p><pre> x2 = resample(x,100,111);
plot(x,'LineWidth',2); hold on; plot(x2,'LineWidth',2); legend('Original','Resampled')</pre><p>This yielded the following graph:</p><img src = "/matlabcentral/answers/uploaded_files/58457/ripples.jpg"><p>I have tried to get rid of the ripples by manipulating the value <b>n</b> of the antialiasing filter (y = resample(x,p,q, <b>n</b>)). The best solution I got was with n=4, which yielded this:</p><img src = "/matlabcentral/answers/uploaded_files/58459/n=4.jpg"><p>which is better, but clearly still not good enough. If I increase the value of n above 4, it gets worse. At this point I am not sure how to handle this issue, and any help would be much appreciated! I don't want to necessarily use the function resample, the main thing I am trying to do here is to reduce my 111-frames long vector into a 100-frames long one, while retaining as much of the data as possible.</p><p>Thanks.</p>Guido Ascensohttp://nl.mathworks.com/matlabcentral/profile/authors/6284843-guido-ascensotag:nl.mathworks.com,2005:Question/3011752016-08-28T19:38:50Z2016-08-28T20:27:18Zmatlab R2016a installed but giving a window showing many java errors when i m opening it ?<p>i have installed matlab R2016a in windows 10 64bit .it was installed alright and activated too ..but when i am opening it it gives a window showing many java errors (the picture I attached).??</p>Qasim Nasirhttp://nl.mathworks.com/matlabcentral/profile/authors/8542384-qasim-nasirtag:nl.mathworks.com,2005:Question/3011732016-08-28T19:33:33Z2016-08-28T20:25:29ZHow to disable specific items from a popup menu by using a logical vector of the same length of the string of the popup menu?<p>Hello , I need some help with a problem...</p><p>Let's say that I have a cell containing the strings I want for the popup menu, for example</p><pre class="language-matlab">t = cell(1,5);
t{1,1} = 'Hello';
t{1,2} = 'Hi';
t{1,3} = 'Welcome';
t{1,4} = 'Pleased to meet you';
t{1,5} = 'Join us';
</pre><p>and I also have a logical vector</p><pre class="language-matlab">logict = [false true true false true];
</pre><p>after setting the items in the popupmenu by executing</p><pre class="language-matlab">set(handles.popupmenu1,'String',t);
</pre><p>How can I disable some of the items (in this case the 1st one and the 4th one) by using the logical vector logict?</p><p>Thank you very much for the help</p>test runhttp://nl.mathworks.com/matlabcentral/profile/authors/8587928-test-runtag:nl.mathworks.com,2005:Question/3011782016-08-28T20:11:14Z2016-08-28T20:20:38Zmatlab R2016a installed but showing a window with many java errors in startup?<p>i have installed matlab R2016a.it was installed but when I am opening it , it shows a window named "error starting desktop" and there are many errors of java in that window.(I have attached pic of that window)</p><img src = "/matlabcentral/answers/uploaded_files/58461/Screenshot%20(1).png">Qasim Nasirhttp://nl.mathworks.com/matlabcentral/profile/authors/8542384-qasim-nasirtag:nl.mathworks.com,2005:Question/3011722016-08-28T19:30:10Z2016-08-28T20:19:46ZX-Ray & Flat Panel Detector (FPD) for radiographic applications<p>I NEED SOME HINTS TO CONNECT MATLAB TO X-Ray Flat Panel Detector DEVICE (for radio-graphic applications) BY utp
IF THERE IS ANY ONE DID THIS BEFORE , PLEASE LET ME KNOW</p><p>THANKS</p>Ahmed Mahdihttp://nl.mathworks.com/matlabcentral/profile/authors/7413137-ahmed-mahditag:nl.mathworks.com,2005:Question/3011772016-08-28T20:07:49Z2016-08-28T20:07:49ZHow to convert unicode into a string?<p>Hi,</p><p>I have the following string, I want to know how can I convert it into a regular string (it is originally contains arabic characters)?</p><pre class="language-matlab">\u062a\u0648\u062f\u0647 \u0648 \u0634\u0645\u0627\u0631 \u0633\u0627\u0632\u0648\u0627\u0631\u0647\u0647\u0627\u06cc \u0632\u0646\u062f\u0647 \u062f\u0631 \u062c\u0627 \u06cc
</pre><p>Thanks in advance.</p>Ive Ivehttp://nl.mathworks.com/matlabcentral/profile/authors/3399872-ive-ivetag:nl.mathworks.com,2005:Question/3011162016-08-27T22:13:17Z2016-08-28T19:59:54Zhow i can get all row of data from a table ??<p>hi ;</p><p>please i want to get all data of row in the table , how can i</p><img src = "/matlabcentral/answers/uploaded_files/58450/ta.PNG"><p>do this ??</p>reda yagoubhttp://nl.mathworks.com/matlabcentral/profile/authors/7685343-reda-yagoubtag:nl.mathworks.com,2005:Question/3011742016-08-28T19:38:20Z2016-08-28T19:42:29ZNeed help on neural network train test and validation accuracy<p>My data set have 420 images(24 features each). there are 160 for train. 20 for validation. 240 for testing.
my problem is, after writing this code am getting 100% accuracy which is absurd. plz help me in this matter as am not sure if my code is correct or not.</p><pre class="language-matlab">% Solve a Pattern Recognition Problem with a Neural Network
</pre><pre class="language-matlab">load('ftrmat420.mat'); %420 x 24
load('class_test.mat'); %1 x 420
</pre><pre class="language-matlab">x=transpose(ftrmat420);
t=class_test;
</pre><pre class="language-matlab">inputs = x
targets = t
</pre><pre class="language-matlab">% Create a Pattern Recognition Network
hiddenLayerSize = 10;
net = patternnet(hiddenLayerSize);
</pre><pre class="language-matlab">% Set up Division of Data for Training, Validation, Testing
%net.divideParam.trainRatio = 30/100;
%net.divideParam.valRatio = 13/100;
%net.divideParam.testRatio = 57/100;
</pre><pre class="language-matlab">%[trainInd,valInd,testInd] = divideind(420,241:420,1:10,1:240);
</pre><pre class="language-matlab">net.divideFcn = 'divideind';
net.divideParam.trainInd = 261:420;
net.divideParam.valInd = 241:260;
net.divideParam.testInd = 1:240;
</pre><pre class="language-matlab">% Train the Network
[net,tr] = train(net,inputs,targets);
</pre><pre class="language-matlab">% Test the Network
outputs = net(inputs);
errors = gsubtract(targets,outputs)
performance = perform(net,targets,outputs)
</pre><pre class="language-matlab">% View the Network
view(net)
</pre><pre class="language-matlab">% Plots
% Uncomment these lines to enable various plots.
figure, plotperform(tr)
figure, plottrainstate(tr)
figure, plotconfusion(targets,outputs)
</pre><pre class="language-matlab">[c,cm] = confusion(targets,outputs)
</pre><pre class="language-matlab">fprintf('Percentage Correct Classification : %f%%\n', 100*(1-c));
fprintf('Percentage Incorrect Classification : %f%%\n', 100*c);
</pre><pre class="language-matlab">figure, ploterrhist(errors)
</pre><pre class="language-matlab">trainTargets = targets .* tr.trainMask{1};
valTargets = targets .* tr.valMask{1};
testTargets = targets .* tr.testMask{1};
</pre><pre class="language-matlab">trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)
</pre>debasmita bhoumikhttp://nl.mathworks.com/matlabcentral/profile/authors/7598996-debasmita-bhoumiktag:nl.mathworks.com,2005:Question/1294152014-05-13T12:19:20Z2016-08-28T19:22:05ZSimScape dynamic compressor / fan modelling with characteristic curve of Pressure Difference to Volumeflow<p>Hi Community,</p><p>I am currently working on my masterthesis and want to start with physical modelling using Simscape.
Therefore I try to model my air-ventilation test bench as a simscape model with the one restriction that I dont have the SimHydraulic Toolbox.</p><p>My Problem consists of the fact that I want to model a <b>realistic Fan-Unit</b> which "feels" the counterpressure of the control path behind it (like CAVs, Ducts, etc.) and calibrates the volumeflow similar to the characteristic V_flow/Pressure Difference-Curve I got from the Fan-Producer.</p><p>Therefore I made a small example to find out, how I can solve the Problem and find stable numerical Solutions for it.
The characteristic curves for a fan and a duct look like this (Fan starts in Point (0,400) the colors can hardly been seen):</p><img src = "/matlabcentral/answers/uploaded_files/12647/SystemPlot.jpg"><p>the System should end up in the crossingpoint somewhere around 9.54 m3/h where the fan produces the same pressure difference as the duct uses up.</p><p>so i wrote a "duct.ssc" model with the curve:</p><pre> component Duct < foundation.pneumatic.vertical_branch</pre><pre> parameters
resistance = {1/10000, 'Pa*s^2/kg^2'};
end</pre><pre> parameters (Access = private)
gas_flow_reference_conv = {1, 'kg/s/Pa^2' }; % Mass flow rate unitconvert
gas_flow_unit= {1, 'kg/s'};
end</pre><pre> equations</pre><pre> gas_flow == sqrt(pressure_difference/resistance);
% Heat equation
temperature_difference == 0;
end</pre><pre> end</pre><p>And the "Fan.ssc" Model based on a pipe model of mathworks:</p><pre class="language-matlab">component Fan_v2 < foundation.pneumatic.absolute_branch
</pre><pre> parameters(Access = private)</pre><pre> p_min = { 0.01, 'Pa' }; % Minimum absolute pressure expected in simulation
T_min = { 0.01, 'K' }; % Minimum absolute temperature expected in simulation
p_gradient_min = { 100, '1/Pa' }; % 1/p_min
T_gradient_min = { 100, '1/K' }; % 1/T_min
p_offset_min = { log(0.01), '1' }; % log(p_min)
T_offset_min = { log(0.01), '1' }; % log(T_min)
T_unit = { 1, 'K'}; % Units of temperature
p_unit = { 1, 'Pa'}; % Units of pressure
gas_flow_reference_conv = {1, 'kg/s/Pa^2' }; % Mass flow rate unitconvert
gas_flow_unit= {1, 'kg/s'};
end</pre><pre> equations</pre><pre> let
% Use logs of absolute pressures and temperatures plus linear extrapolation for
% pressures and temperatures below T_min and p_min to prevent divide by zero
% in flow equations.
logP1 = if p1<p_min, p_offset_min + p_gradient_min*(p1 - p_min) else log(p1) end;
logP2 = if p2<p_min, p_offset_min + p_gradient_min*(p2 - p_min) else log(p2) end;
logT1 = if T1<T_min, T_offset_min + T_gradient_min*(T1 - T_min) else log(T1) end;
logT2 = if T2<T_min, T_offset_min + T_gradient_min*(T2 - T_min) else log(T2) end;</pre><pre> % Flow direction - "dir" is positive if flow is from port A to port B, otherwise negative
% should not happen, maybe create something like a lock valve
% A fan is a compressor it wants to compress the air therefore p2 must be larger than p1</pre><pre> dir = if p2>p1, 1 else -1 end;
% Upstream and downstream pressures and temperatures
[p_u, p_d, T_u, T_d] = if dir>0, ...
p_unit*exp(logP1); p_unit*exp(logP2); T_unit*exp(logT1); T_unit*exp(logT2) else ...
p_unit*exp(logP2); p_unit*exp(logP1); T_unit*exp(logT2); T_unit*exp(logT1) end;
in
if dir>0 %a->B
G==400*gas_flow_unit-(p_u-p_d)^2*gas_flow_reference_conv;
else %B->A
G==0;
end</pre><pre> Q1 == G*A.c_p*T1;
Q2 == -G*A.c_p*T1;
end </pre><pre> end
end</pre><p>But this dont works, I always get something like:</p><pre class="language-matlab">steady state solve failed to converge.
...Nonlinear solver to advance time one step failed to converge due to Linear Algebra error. Failed to solve using iteration matrix.
</pre><pre class="language-matlab">......Equations of one or more components may be dependent or inconsistent. This can cause problems in transient initialization. Here is the set of components involved:
'Fan_Min_Example/ Pneumatic Atmospheric Reference '
Equation location is:
'C:/Program Files/MATLAB/R2014a/toolbox/physmod/simscape/library/m/+foundation/+pneumatic/+elements/atmospheric_reference.ssc' (line 26)
</pre><pre class="language-matlab">'Fan_Min_Example/Constant Volume Pneumatic Chamber'
Equation locations are:
'C:/Program Files/MATLAB/R2014a/toolbox/physmod/simscape/library/m/+foundation/+pneumatic/vertical_one_port.ssc' (line 29)
'C:/Program Files/MATLAB/R2014a/toolbox/physmod/simscape/library/m/+foundation/+pneumatic/+elements/chamber.ssc' (line 39)
</pre><pre class="language-matlab">'Fan_Min_Example/Duct'
Equation locations are:
'C:/Program Files/MATLAB/R2014a/toolbox/physmod/simscape/library/m/+foundation/+pneumatic/vertical_branch.ssc' (line 28)
'D:/Studium/Masterarbeit/Matlab/Simscape/Library/+MasterarbeitSimscape/+PneumaticElements/Duct.ssc' (line 19)
</pre><pre class="language-matlab">'Fan_Min_Example/Thermal Reference'
Equation location is:
'C:/Program Files/MATLAB/R2014a/toolbox/physmod/simscape/library/m/+foundation/+thermal/+elements/reference.ssc' (line 22)
Component: Simulink | Category: Block error
</pre><p>I hope I described my problem or the things I want to do well enough and look foreward to your answers. Just to let you know my system is built up like this:</p><p><b>atmosphere reference <a href = "-">-</a> Fan-Modell <a href = "-">-</a> Const. Vol. Pneu. Chamber <a href = "-">-</a> Duct <a href = "-">-</a> Atmo. reference</b></p>Claushttp://nl.mathworks.com/matlabcentral/profile/authors/4594337-claustag:nl.mathworks.com,2005:Question/820672013-07-15T09:56:54Z2016-08-28T19:18:27ZIs there any robust solution to match two images and find the percentage of match between them in MATLAB ?<p>Problem description -</p><p>->say we already have some no of template(base) images in one folder</p><p>Input -</p><pre> - Image to find its perfect matching image</pre><p>Output -</p><pre> -Matched Image (if found)</pre><pre> -Otherwise Message - no matching found </pre><p>I need robust solution to this ..</p><p>I have tried using SURF Features but its not giving me robust output
meaning it sometimes gives wrong match - though it its giving quite good result but not 100 %</p><p>Here is the rough logic of my current algorithm :</p><pre> Input_Image_gray = rgb2gray(Input_Image);</pre><pre> Input_keys = detectSURFFeatures(Input_Image_gray);</pre><pre> [Input_features Input_validPts] = extractFeatures(Input_Image_gray, Input_keys);</pre><p>----iterate for loop for the Template images we have in a Folder</p><pre> templateImage=templateImagesArray{loopCounter};</pre><pre> ref_img_gray = rgb2gray(templateImage);</pre><pre> ref_keys=detectSURFFeatures(ref_img_gray);</pre><pre> [~, MATCH_METRIC] = matchFeatures(ref_features,Input_features ,'MatchThreshold',3);</pre><p>-- Calculate percentage for each image on the base of MATCH_MATRIC</p><pre> if percentage > 50</pre><pre> display the matched Image</pre><pre> otherwise display message - no matching image fond</pre><p>----end loop</p><p>please share if any body has any idea regarding how to achieve this</p><p>Thanks in advance..</p>meghna bhatthttp://nl.mathworks.com/matlabcentral/profile/authors/3381461-meghna-bhatttag:nl.mathworks.com,2005:Question/2177092015-05-20T09:22:45Z2016-08-28T19:16:54ZMux to Bus error message<p>I'm getting a strange error when trying to run one of our models in simulink: I'm being told 'The block diagram 'Filename' uses bus signals. However, the 'Mux blocks used to create bus signals' diagnostic is not configured to 'error'. To prevent modeling errors:'</p><p>Why am I getting an error message for something I've deliberately turned off? Due to the way the model interfaces with our software it has to have a mux creating a bus otherwise it won't work so I can't replace the muxes with buses.</p>Matthew Enrighthttp://nl.mathworks.com/matlabcentral/profile/authors/6543065-matthew-enrighttag:nl.mathworks.com,2005:Question/3011652016-08-28T15:51:41Z2016-08-28T19:11:14ZODE suite for solving switched systems<p>I have the following code.
The initial conditions for X : [0;0;0;0]. sw = 0. n =100. h = 1e-9.</p><pre class="language-matlab">for k = 1 : n
if (sw(k) == 0 && X(2,k)> 0.7 ) || (sw(k) == 1 && X(1,k) >0)
sw(k+1) = 1;
X(:,k+1) = X(:,k) +h*(A1*X(:,k) + B1*u);
else
sw(k+1) =0;
X(:,k+1) = X(:,k) +h*(A0*X(:,k) + B0*u);
end
</pre><pre> end</pre><p>I need to execute this code in the ODE suite. How do I take check sw and X after each iteration to see which of the two ODEs is to be solved.</p>Hadhiq Khanhttp://nl.mathworks.com/matlabcentral/profile/authors/8550120-hadhiq-khantag:nl.mathworks.com,2005:Question/3011152016-08-27T21:40:23Z2016-08-28T19:01:23ZChanging table columns to the same type<p>I am downloading data from the internet using 'urlread' function. I am using this to analyse football stats for my betting. So there are columns for HomeTeam, AwayTeam, Shots, Possesion etc..
I want all these columns to be of the same type! Preferably just numbers. I tried doing a for loop with if statements trying to highlight certain columns to change them from, say, 'Arsenal' to just a 1. (This is because arsenal is first alphabetically) So something like</p><p>for ii=1:height(data) % This makes sure it goes through all the rows. ./</p><pre class="language-matlab">if data(ii,1)=='Arsenal'
</pre><pre class="language-matlab">data(ii,1)=1; %Data is just matrix with statistics.
</pre><pre> end </pre><p>end</p><p>The error message I get is ''Undefined operator '==' for input arguments of type 'table'.''</p>Andy Hutchinsonhttp://nl.mathworks.com/matlabcentral/profile/authors/7107404-andy-hutchinsontag:nl.mathworks.com,2005:Question/2150032015-05-04T15:03:22Z2016-08-28T18:58:15ZHow to resolve : "Not enough input derivatives were provided for one or more Simulink-PS Converter blocks associated with the highlighted Solver Configuration block, for the solver chosen." ?<p>Hello,</p><p>I'm trying to use a DC motor (combined with a gear box) to make my solid (which I imported from Solidworks) rotate, and to monitor its torque and angular speed.
Here's a screenshot of my workspace :</p><img src = "/matlabcentral/answers/uploaded_files/30312/screen%20matlab.bmp"><p>Every time I hit run, it answered</p><p>"Not enough input derivatives were provided for one or more Simulink-PS Converter blocks associated with the highlighted Solver Configuration block, for the solver chosen. Implicit solvers (ode23t, ode15s, and ode14x) typically require fewer input derivatives than explicit solvers, and local solvers never require any. You can provide more input derivatives by selecting different options (including turning input filtering on or increasing the number of user-provided input derivatives) on the Input Handling tab of Simulink-PS Converter blocks linked below:</p><p>...'matlabprojet3/Revolute - Rotational Interface/Simulink-PS Converter' (1 required, 0 provided)"</p><p>So I tried several solutions including changing the solver to one of those advised, setting the Revolute-Rotational interface to "filter input", or setting the solver to "local solver". All of these changes lead to this other message when I tried to run :</p><p>"Initial conditions solve failed to converge.
...Nonlinear solver to advance time one step failed to converge due to Linear Algebra error. Failed to solve using iteration matrix.</p><p>......Equations of one or more components may be dependent or inconsistent. This can cause problems in transient initialization. Here is the set of components involved:
'matlabprojet3/Ideal Torque Sensor'
Equation location is:
'C:/Program Files/MATLAB/R2013a/toolbox/physmod/simscape/library/m/+foundation/+mechanical/+sensors/torque.ssc' (line 37)</p><p>'matlabprojet3/Revolute - Rotational Interface/Angular Velocity Source'
Equation location is:
'C:/Program Files/MATLAB/R2013a/toolbox/physmod/simscape/library/m/+foundation/+mechanical/+sources/angular_velocity.ssc' (line 37)</p><p>'matlabprojet3/Revolute - Rotational Interface/Torque Sensor'
Equation location is:
'C:/Program Files/MATLAB/R2013a/toolbox/physmod/simscape/library/m/+foundation/+mechanical/+sensors/torque.ssc' (line 37)"</p><p>I'm not really used to using Matlab but I searched around it and on the internet and didn't find how to fix this. Could you please tell me how to get this to work and to get some results in the scopes ?</p><p>Thanks in advance,</p><p>Adrien.</p>Adrien Stellahttp://nl.mathworks.com/matlabcentral/profile/authors/6486991-adrien-stellatag:nl.mathworks.com,2005:Question/3011412016-08-28T11:42:00Z2016-08-28T18:57:20ZCalculating variance in loop<p>Hi, I have 8 years of data and I want to calculate the variance of the same month but different year all together. i.e. Variance of January for all the 8 years. My matrix is 74*115*22168. I know there is the function var, but I'm finding problems to incorporate everything in a loop that does everything in one run. Any help pls</p>MFhttp://nl.mathworks.com/matlabcentral/profile/authors/7464912-mftag:nl.mathworks.com,2005:Question/3011662016-08-28T16:17:19Z2016-08-28T18:54:16Zhow to locate/extract users in circle from randomly distributed many points..? <p>Hi everyone. I have randomly deployed users in a hexagon and circle. The problem i am facing is to locate the users which are in circle, and to find the distance of those users/points from the center of circle. Is there any way that only the users which are in circle can be extracted as shown in figure? Kindly help me with this.</p><img src = "http://www.mathworks.com/matlabcentral/answers/uploaded_files/58455/Capture.PNG">ammara khurshidhttp://nl.mathworks.com/matlabcentral/profile/authors/7612566-ammara-khurshidtag:nl.mathworks.com,2005:Question/3011712016-08-28T17:40:18Z2016-08-28T18:46:23ZProblem with GUI variables from workspace<p>Hello, I have a problem running my GUI. I am defining bunch of variables using "Edit Text". I am signing them to workspace using</p><pre class="language-matlab">assignin('base','variable_name',value);
</pre><p>Then I want to calculate some new variables using those defined in Workspace after Button in GUI is pressed, but when i press the Button I am getting an error that the variable which I want to use in calculation is not defined even though i can see this exact variable visible in Workspace.</p><p>The simplified code goes like this:</p><pre class="language-matlab">function zwrot_tp_o_Callback(hObject, eventdata, handles)
zwrot_tp_o=str2num(get(handles.zwrot_tp_o,'String'));
assignin('base','zwrot_tp_o',zwrot_tp_o);
</pre><p>the same way as shown above I am defining other variables. Then the Button:</p><pre class="language-matlab">function symuluj_Callback(hObject, eventdata, handles)
tmax=1000;
t= [1:tmax]';
x1= zeros(zwrot_tp_o-1,1);
x2= ster_o * ones(zwrot_tk_o - zwrot_tp_o,1);
x3= zeros(tmax-zwrot_tk_o,1);
x=vertcat(x1,x2,x3);
</pre><p>The error occurs in line where I calculate x1, it says that i have undefined "zwrot_tp_o" even though it is in workspace.
So I tried defining that variable once again just above the x1 equation just like: zwrot_tp_o=500 and then it was accepting this variable but was giving the same error about next variable. Any ideas?</p>Jakub Fhttp://nl.mathworks.com/matlabcentral/profile/authors/8583446-jakub-ftag:nl.mathworks.com,2005:Question/561222012-12-09T16:29:11Z2016-08-28T18:45:47ZSimulink Modeling 16 QAM with USRP<p>I am using the Simulink Model QPSK-Receiver and QPSK-Transmitter. Right now i am trying to replace the modulation methode QPSK with 16 QAM and 64 QAM. Although i have borrowed the book < Digital Communications - A Discrete-Time Approach > from Micheal Rice, it didn’t really help me. As written in the book, the Structure of the time synchronization and phase synchronization of the MQAM is the same as of QPSK, there are just short kapitels related to the MQAM and i can’t find enough informations. I have given some thoughts about this problem, My guess is that i have to alter the parameters of those funktion blocks, like AGC, Fine Frequence Compensation and Time Recovery.
The problem i have right now is, i can’t get to understand, how those parameters such as “desired amplitude”, “fine frequence compasition gain”,”kp”,”k0”,”k1” and so on, get to influnce the porformance of the PLL for the phase and time synchronization, and which values i should choose.
I am very thankful when someone can give me some advices.</p><p>Thanks</p><p>With best Regards
Fan Zhang</p>fan zhanghttp://nl.mathworks.com/matlabcentral/profile/authors/2064597-fan-zhangtag:nl.mathworks.com,2005:Question/3011072016-08-27T20:08:05Z2016-08-28T18:45:42ZI have an image of an eye. I wanted to detect and crop the conjunctival region. How should I go about this?<img src = "/matlabcentral/answers/uploaded_files/58428/conj10.jpg">Medha Sharmahttp://nl.mathworks.com/matlabcentral/profile/authors/8581757-medha-sharmatag:nl.mathworks.com,2005:Question/3011432016-08-28T12:00:58Z2016-08-28T18:43:03ZHow to call sub or superclass constructor when recursively creating objects<p>Hi,</p><p>I'm writing a tree class. I'd like a superclass to contain generic construction / maintenance methods, then be able to subclass it for a range of different, more specific purposes.</p><p>Something like:</p><pre class="language-matlab">classdef SuperTree < handle
</pre><pre> properties
BranchLocation
Parent
Children
end</pre><pre> methods</pre><pre> function obj = SuperTree(varargin)
% construct the the object
end</pre><pre> function subdivide(obj, limit_criterion)
% Lots of code that's difficult to maintain and
% shouldn't be overloaded in a subclass
if limit_criterion
% Create child branches
chld1 = SuperTree(args);
chld2 = SuperTree(args);
obj.Children = [chld1; chld2]
end</pre><pre> end
end</pre><p>The problem is that if I create a subclass, then the subdivision method still makes a call to SuperTree() to construct its children.</p><p>Is there a way of getting (say) a handle to the constructor function of the current object? I don't want to be overloading the subdivide method for each of my subclasses. Something like this would be ideal:</p><pre> function subdivide(obj, limit_criterion)
% Lots of code that's difficult to maintain and
% shouldn't be overloaded in a subclass
if limit_criterion
% Create child branches
chld1 = obj.Constructor(args);
chld2 = obj.Constructor(args);
obj.Children = [chld1; chld2]
end</pre><p>At the moment I'm working around this with a small utility method, that I overload in each subclass. Working? Yes. Elegant? No. So I'd be interested in any 'proper' solutions.</p><p>Thanks!</p><p>Tom</p>Tom Clarkhttp://nl.mathworks.com/matlabcentral/profile/authors/5402650-tom-clarktag:nl.mathworks.com,2005:Question/769932013-05-26T05:28:14Z2016-08-28T18:42:03ZCompressed Air energy Storage System Simscape - Continue to get errors <p>Hi,
I have a model of a compressed air energy storage system, I am havingin trouble getting the model to run without error due to the pneumatic motor.</p><p>Is there anyone that could provide some assistance with these errors.</p><p>The system consists of the following components</p><p>PV Cell</p><p>DC motor</p><p>Air Compressor</p><p>Air motor</p><p>AC generator</p><p>Each time I run the simulation I get this error which goes above my knowledge.</p><p>The error is;</p><p>"Steady state solve failed to converge.
...Nonlinear solver to advance time one step failed to converge due to Linear Algebra error. Failed to solve using iteration matrix.</p><p>......Equations (including nonlinear equations) of one or more components may be dependent or inconsistent. This can cause problems in transient initialization. Here is the set of components involved:
'Final/Pneumatic Motor'
Equation location is:
'C:/Program Files/MATLAB/R2013a/toolbox/physmod/simscape/simscapedemos/+PneumaticMotor/PneumaticMotor.ssc' (line 81)</p><p>'Final/Rotational Pneumatic- Mechanical Converter'
Equation location is:
'C:/Program Files/MATLAB/R2013a/toolbox/physmod/simscape/library/m/+foundation/+pneumatic/+elements/rotational_converter.ssc' (line 99)"</p><p>If you can help me please let me know and I can send you the file, alternatively if someone can tell me how to upload it to this message I will do that.</p><p>Thanks for your time
Regards,
Kayne</p>kaynehttp://nl.mathworks.com/matlabcentral/profile/authors/1640762-kaynetag:nl.mathworks.com,2005:Question/3011592016-08-28T14:58:39Z2016-08-28T18:35:25ZHow do I find the closest points in a matrix <p>I have a matrix of 1682 rows. For understanding I am giving you a small example to achieve my desired task:</p><pre class="language-matlab">A=[1 2 4 5 100;
2 3 4 5 1;
3 4 5 6 7;
2 2 3 4 4;
1 1 1 2 2 0;
0 1 0 1 2]
</pre><p>OK first I will look for a vector where 100 exists -- here it is first column. Now what I need is its closest vectors in sorted form. I can use any number to change the closest vectors, so if it's 1 then it must return the min distance, but if its 3 it must return the closest 3 distances from that vector which i searched for.</p><p>For my task, I need minimum 10 closest distance points. I must know their column numbers for referencing.</p><p>Kindly help me in this task.</p>abdul wahab azizhttp://nl.mathworks.com/matlabcentral/profile/authors/7148942-abdul-wahab-aziztag:nl.mathworks.com,2005:Question/3011292016-08-28T05:19:07Z2016-08-28T18:34:39ZHow to insert a saved .png figure into a subplot which is being created in a for loop?<p>Hello Friends,</p><p>I have the following code</p><pre class="language-matlab">for k = 1:2
subplot(1,3,k)
plot(randi(10,k));
end
</pre><p>I want to insert a saved <b>.png</b> (I prefer <b>.png</b>, but if it is easier for <b>.fig</b>, it is also ok) into this subplot which is being created in for loop at position <b>subplot(1,3,1)</b>. This way, the inserted figure will come at the first position moving other two subfigures to the next available positions.</p><p>I will appreciate any advise!</p>hello_worldhttp://nl.mathworks.com/matlabcentral/profile/authors/5403394-hello_worldtag:nl.mathworks.com,2005:Question/3005372016-08-23T04:16:35Z2016-08-28T18:19:59ZHow to get starting and ending limits of each silence interval?<p>I have a code in which a Boolean vector(vad) the same length as the audio returns '1' for audio and '0' for silence. Now i want to get limits of each starting and ending silence interval... for example if silence bits start from 2 to 5 and 7 to 9 then i want to get this 2 to 5 and 7 to 9 limits. By using voicebox function activlev i get this logical array vad. <a href = "http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/doc/voicebox/activlev.html">http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/doc/voicebox/activlev.html</a></p><p>Can anyone help me?</p>ayesha jabeenhttp://nl.mathworks.com/matlabcentral/profile/authors/8455756-ayesha-jabeentag:nl.mathworks.com,2005:Question/3010772016-08-27T12:05:12Z2016-08-28T18:05:33ZHow can I differentiate my B-Splines?<p>Trying to differentiate these B-Splines over [0,1], where
n : order of b-spline,
u : breaks.</p><p>I do not have the curve fitting toolbox and I have already tried to find something here/on stackexchange, but nothing seems to work. I'd appreciate help or explanation/ pointing out my mistakes or just plain code to make it work. Thanks!</p><pre class="language-matlab">function y = splines(u,n)
if n>2
y = ((u/(n-1)).*splines (u,n-1))+ (((n-u)/(n-1)).*splines(u-1,n-1));
else
y = zeros(size(u));
ind = find(u>0 & u<2) ;
y(ind) = 1 - abs(u(ind)-1);
end
end
</pre>Fabian Schaumhttp://nl.mathworks.com/matlabcentral/profile/authors/8531907-fabian-schaumtag:nl.mathworks.com,2005:Question/3011612016-08-28T15:02:31Z2016-08-28T18:00:45Zhow to use KNN method <p>i want to use this method like if i have any vector and i want its neareast neighbours in whole matric
for example by desired vector is [1 2 3] and i have 1000 rows so it must return me closest points with their cols information where they exist</p>abdul wahab azizhttp://nl.mathworks.com/matlabcentral/profile/authors/7148942-abdul-wahab-aziztag:nl.mathworks.com,2005:Question/3011462016-08-28T12:15:56Z2016-08-28T17:59:16ZWTMM for 1-D <p>this function have rshift and lshift which is not defined.</p>NASSREhttp://nl.mathworks.com/matlabcentral/profile/authors/5899324-nassretag:nl.mathworks.com,2005:Question/3011672016-08-28T16:24:27Z2016-08-28T17:57:37ZPutting a matrix with no breaks<p>I have a matrix size 380 by 24. However, it breaks it up! i.e it reads ''columns 19 through 24'' which is inconvenient for me. I can change this by using num2str but I don't want my data in strings. Any ideas?</p>Andy Hutchinsonhttp://nl.mathworks.com/matlabcentral/profile/authors/7107404-andy-hutchinsontag:nl.mathworks.com,2005:Question/3011222016-08-28T00:39:06Z2016-08-28T17:40:58ZWhy is Bayesian regularization backpropagation (Neural Network Toolbox) so very very slow?<p>Empirically I've found with a challenging pattern recognition problem I'm working on, that Bayesian regularization backpropagation (trainbr) outperforms more standard tools such as trainlm, trainscg and trainrp by quite a bit. But, it takes an extraordinarily longer time to compute. In its original formulation (MacKay 1992), Bayesian regularization required calculation of the Hessian matrix, which is very computationally demanding, and would account for the long time. However, in Foresee 1997 (both works cited in Matlab doc for trainbr), an alternative was developed that claims to reduce the computational challenge to be similar to e.g. trainlm. This latter work is cited in the documentation, but is it implemented? Can I find a library somewhere that implements it? I'm pretty confident that trainbr as implemented in the Neural Network Toolbox requires calculation of the Hessian, because it refuses to run on a GPU, identifying lack of support for inversion of the (related) Jacobian as the reason. But, I'd be happy to be educated on that.</p>jkrhttp://nl.mathworks.com/matlabcentral/profile/authors/8350685-jkrtag:nl.mathworks.com,2005:Question/3003522016-08-21T14:57:00Z2016-08-28T17:40:33ZWhat is wrong with my code for a double pendulum?<p>I tried to replicate figs 2 and 3 from a study on a double pendulum model of a tennis stroke. Here is the study (A double pendulum model of tennis strokes. Rod Cross. Uni of Sydney, 2006) - <a href = "http://www.physics.usyd.edu.au/~cross/PUBLICATIONS/49.%20TennisDPend.pdf">Study</a> I initially tried to integrate all the equations and constants from the study into Excel, but I couldn't seem to replicate the figs 2 or 3. Link for excel spreadsheet - <a href = "https://docs.google.com/spreadsheets/d/1iq1EEVaS9KmKIusScJzO5hKExXXuS8Vz7u5QtmIs8VQ/edit#gid=0">Spreasheet</a></p><p>I then turned to Matlab, in the hope I could find where I went wrong. I used a template pendulum file on the matlab site, from Sathyanarayan Rao, and altered it to integrate the equations from the study. I'struggling to get past the error message in the pend.m file. I've attached my code. The code is for Fig 2 from the study.</p><p>I'm getting the error message "Not enough input arguments" for the equations bt, P and Q. My take on the error is that the states of the system y (1), y(2), y (3), y (4) are included in these equations and they're below bt, P and Q in the code. However, I can't put the equations for y 1,2,3 and 4 above the equations for bt,P and Q, as they include bt, P and Q, so the same error occurs.</p><p>For clarity, my code for bt, P and Q is</p><pre> bt = y(3)-y(4);
P = (C1-C2)-(B*y(4)^2)*SIN(bt)+S*(ax*COS(y(3))+(g+ay)*SIN(y(3)));
Q = C2+B*y(2)^2*SIN(bt)+R*(ax*COS(y(3))+(g+ay)*SIN(y(3)));</pre><p>The equations for the systems states is;</p><pre class="language-matlab">yprime(1) = - y(2);
yprime(3)= - y(4) ;
yprime(2)= (P*i2-Q*B*cos(bt))/(A*i2-B^2*cos(bt)^2) ;
yprime(4)= (Q*A-P*B*cos(bt))/(A*i2-B^2*cos(bt)^2) ;
</pre>Kiefhttp://nl.mathworks.com/matlabcentral/profile/authors/8282987-kieftag:nl.mathworks.com,2005:Question/3011572016-08-28T14:54:37Z2016-08-28T17:38:19ZHow to solve matrix riccati differential equation in MATLAB without using MATLAB functions like care,are,dare?<p>Hi,</p><p>I am working on designing of LQR controller and I need to solve riccati equation without using MATLAB functions which are available to solve riccati equation so that I can convert the MATLAB code to c code easily. So can any one help me with this problem</p>nikita ghaghttp://nl.mathworks.com/matlabcentral/profile/authors/8018421-nikita-ghagtag:nl.mathworks.com,2005:Question/3011512016-08-28T12:54:23Z2016-08-28T17:25:55ZHow can I get the outputs from the result of additional Test in a neural network Tool box?<p>I already tried a Fitting problem with inputs of 87x4 matrix and a target 87x22 matrix. The network performance was good enough, then I tried to perform additional test with a different 32x4 matrix as inputs and same targets a 32x19 matrix. I ran the Test network. It was ok but there is no way to get the outputs of this last performance. How can I get the outputs of this additional test?</p>Orlando Yaguashttp://nl.mathworks.com/matlabcentral/profile/authors/4734652-orlando-yaguastag:nl.mathworks.com,2005:Question/3011682016-08-28T16:48:39Z2016-08-28T17:18:29Zhow to calculate indefinite integral with quadgk?<p>hello i have a problem solving indefinite integral.</p><p>how to solve this problem? (attach picture)</p><p>i already create this syntax :</p><pre class="language-matlab">y =@(x)((x-r).*(1-(exp(-x./b))));
a = quadgk(y,r,inf);
</pre><p>But always error and says :</p><pre class="language-matlab">Error in Untitled2 (line 2)
a = quadgk(y,r,inf);
</pre><p>thx before, i hope someone can help me with this problem... :)</p><img src = "/matlabcentral/answers/uploaded_files/58454/test.jpg">kevin liantohttp://nl.mathworks.com/matlabcentral/profile/authors/8569906-kevin-liantotag:nl.mathworks.com,2005:Question/3010712016-08-27T10:26:39Z2016-08-28T17:07:43ZNot enough input arguments - Function<p>This is probably easy to spot and solve but I'm new to MATLAB so am having trouble with this.</p><p>I would greatly appreciate anybody proposing a solution to the function I have below. The error message is at the bottom and states that there are not enough input arguments. The variable 'data' is a single matrix with dimensions 9x52x2.</p><pre class="language-matlab">%%
</pre><pre class="language-matlab">function X = CreateFeatures(data,fs,numCh);
</pre><pre class="language-matlab">% ==================================================================
% ============ Preallocations and definitions ======================
% ==================================================================
</pre><pre class="language-matlab">numF = 18; % Number of features
</pre><pre class="language-matlab">fs = 256;
</pre><pre class="language-matlab">numCh = 8;
</pre><pre class="language-matlab">X = zeros(1, numF*numCh); % Preallocate
</pre><pre class="language-matlab">% ==================================================================
% =================== Sub-functions ================================
% ==================================================================
</pre><pre class="language-matlab">function count = zerox(data) % sub-function: Zero-Crossings
</pre><pre> t = 1:length(data)-1;</pre><pre> count = 0; </pre><pre> for i = 1:length(t)</pre><pre> if sign(data(i)) ~= sign(data(i+1))</pre><pre> count = count + 1;</pre><pre> end</pre><pre> end</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">function Ent = SpecEnt(data) % sub-function: Spectral Entropy
</pre><pre> x = fftshift(fft(data));</pre><pre> PSD = abs(x).^2;</pre><pre> sum = 0;</pre><pre> for i = 1:length(data)</pre><pre> sum = sum + PSD(i);
end</pre><pre> PSDn = PSD/sum;</pre><pre> Ent = 0.0;</pre><pre> for i = 1:length(data)</pre><pre> Ent = Ent-PSDn(i)*log2(PSDn(i)+eps); % eps is the floating-point
% relative accuracy</pre><pre> end</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">function mob = Hjorth_mob(data) % sub-function: Mobility
</pre><pre> h = 1; %step size for approximated derrivative</pre><pre> sd = var(data);</pre><pre> sdx = var(diff(data)/h); %sd of the first derivative of the signal</pre><pre> mob = sqrt(sdx/sd);</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">function com = Hjorth_com(data) % sub-function: Complexity
</pre><pre> h = 1; %step size for approximated derrivative</pre><pre> sd = var(data);</pre><pre> xx = diff(data)/h;</pre><pre> sdx = var(xx); %sd of the first derivative of the signal</pre><pre> sdxx = var(diff(xx)/h);</pre><pre> com = sqrt((sdxx/sdx)/(sdx/sd));</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">% defining constants for input to the aar function below
</pre><pre class="language-matlab">Mode = [1,2]; % Mode = [aMode vMode]
</pre><pre class="language-matlab">MOP = [5,0]; % model order (number of parameters = 5)
</pre><pre class="language-matlab">% ===================================================================
% =============== Creating the feature vector =======================
% ===================================================================
</pre><pre class="language-matlab">for j = 0:numCh-1 % Loop over channels
</pre><pre> X(numF*j+1) = log10(var(data(j+1,:))); % Hjorth: activity (variance)</pre><pre> X(numF*j+2) = zerox(data(j+1,:)); % Zero-crossings</pre><pre> X(numF*j+3) = SpecEnt(data(j+1,:)); % Spectral entropy</pre><pre> X(numF*j+4) = log10(abs(wentropy(data(j+1,:),'shannon'))); % Shannon entropy</pre><pre> X(numF*j+5) = log10(Hjorth_mob(data(j+1,:))); % Hjort: mobility</pre><pre> X(numF*j+6) = log10(Hjorth_com(data(j+1,:))); % Hjort: complexity</pre><pre> AllParam = aar(data(j+1,:)', Mode, MOP)' ; % finding all AAR</pre><pre> % parameters using function from Biosig</pre><pre> X(numF*j+(7:11)) = mean(AllParam(:,6:end),2); % mean over each row
% (5 AAR param/channel)</pre><pre> X(numF*j+12) = log10(bandpower(data(j+1,:),fs,[0.5 4])); % BP delta</pre><pre> X(numF*j+13) = log10(bandpower(data(j+1,:),fs,[4 8])); % BP theta</pre><pre> X(numF*j+14) = log10(bandpower(data(j+1,:),fs,[8 13])); % BP alpha</pre><pre> X(numF*j+15) = log10(bandpower(data(j+1,:),fs,[14 30])); % BP beta</pre><pre> X(numF*j+16) = log10(bandpower(data(j+1,:),fs,[31 70])); % BP gamma</pre><pre> X(numF*j+17) = log10(bandpower(data(j+1,:),fs,[71 100])); % BP high gamma </pre><pre> X(numF*j+18) = log10(bandpower(data(j+1,:),fs,[0.5 100])+eps); % BP total</pre><pre class="language-matlab">end
end
</pre><p>The error message reads:</p><pre class="language-matlab">>> CreateFeatures
Not enough input arguments.
</pre><pre class="language-matlab">Error in CreateFeatures (line 88)
X(j) = log10(var(data(j+1,:))); % Hjorth: activity (variance)
</pre>Stephan Raczakhttp://nl.mathworks.com/matlabcentral/profile/authors/5663833-stephan-raczaktag:nl.mathworks.com,2005:Question/3011702016-08-28T17:06:15Z2016-08-28T17:06:15ZHow do the 'weights' work in the glmfit function?<p>I am working with the <i>glmfit</i> function. The current line of code is:</p><pre class="language-matlab">b = glmfit(X,y,'binomial','link','logit');
</pre><p>In certain cases, some data points in X are more important than others and I want to modify the log-likelihood with weights.</p><p>Lets say I have data points x1, x2, ... , x10. x1 is the least important and x10 is the most important, and it follows with a linear increasing order.</p><p>From the documentation (mathworks.com/help/stats/glmfit.html): "such as the inverses of the relative variance of each observation". That sentence suggests that the weights will be in units matching square of variables, so that would suggest (10:-1:1).^2' is what I am looking for. However, it could be that the help wasn't written well and (10:-1:1) is what I want. Which one is correct?</p>Robin Grenholmhttp://nl.mathworks.com/matlabcentral/profile/authors/6961997-robin-grenholmtag:nl.mathworks.com,2005:Question/3011692016-08-28T17:05:32Z2016-08-28T18:01:28ZAny API s to create simulink Inport and Outport blocks ?<p>I am trying to create an inport block and an outport block and connect the two blocks indicating inport = outport.</p><p>How can i achieve this using API's from Matlab ? I just came across class Simulink.BlockDiagram, but i dont understand how do i select Inport block and set the block parameter values using matlab</p><p>Any help, would be thankful !!</p>Vinay Sheshadri http://nl.mathworks.com/matlabcentral/profile/authors/8478863-vinay-sheshadritag:nl.mathworks.com,2005:Question/3011602016-08-28T15:01:51Z2016-08-28T16:59:07Zhello , my output is display In terms of [e] as following . how to transform the out put to numerical values without e , and how sort the interval in output by descending<p>out =</p><pre> 1.0e+04 *</pre><pre> 1.4000 1.5000
1.7000 1.8000
1.9000 2.0000
1.5000 1.5250
1.5250 1.5500
1.5500 1.5750
1.5750 1.6000
1.6000 1.6333
1.6333 1.6667
1.6667 1.7000
1.8000 1.8500
1.8500 1.9000</pre>mohammed hamdyhttp://nl.mathworks.com/matlabcentral/profile/authors/8604732-mohammed-hamdytag:nl.mathworks.com,2005:Question/3011632016-08-28T15:35:40Z2016-08-28T16:57:53ZCan I buy home license Simscape Power Systems for student licence Matlab<p>I already bought student license Matlab with some toolboxes, I got error for the number of non virtual blocks as it limited by 1000 for Simscape Power Systems. is it possible to upgrade this toolbox only to home licence? and is it also limited by 1000 blocks?</p>Mostafa Hamoodhttp://nl.mathworks.com/matlabcentral/profile/authors/8563159-mostafa-hamoodtag:nl.mathworks.com,2005:Question/3011642016-08-28T15:49:17Z2016-08-28T16:51:57ZWhat is the purpose of fstop<p>Hi everyone,</p><p>I was using the filter design (fdatool) in Matlab.</p><p>I noticed that there are these parameters: Fpass, Fstop, Wpass and Wstop.</p><p>I have checked the documentation but there is no explanation for these parameters.</p><p>What are the purpose of these parameters?</p>programmingnewbiehttp://nl.mathworks.com/matlabcentral/profile/authors/8289574-programmingnewbietag:nl.mathworks.com,2005:Question/3011622016-08-28T15:35:06Z2016-08-28T16:15:43Zwhy does findpeaks detects minimas?<p>I got the data of an acceleration sensor and I want to detect only the local maximas, I used</p><pre> plot(data);
findpeaks(data);</pre><p>but it also detected the minimas, but why?</p><p>With</p><pre class="language-matlab">findpeaks(data,'MINPEAKHEIGHT',2);
</pre><p>it worked as I expected the function to work, but I can't use 2 as a static threshold for my application.
Did I something wrong, that it also detects the minimas or do I have to find a way to implement an adaptive threshold?</p><img src = "/matlabcentral/answers/uploaded_files/58453/findpeaks.png">Kai Hansmannhttp://nl.mathworks.com/matlabcentral/profile/authors/6385293-kai-hansmanntag:nl.mathworks.com,2005:Question/3011492016-08-28T12:41:24Z2016-08-28T15:58:29Zhow can I store values generated from a nested loop into an arrray ?<p>if I have this code :-</p><pre class="language-matlab">function S = triangle_wave(n)
S = zeros(1,1001); %preallocation
e = [];
for t = 0:((4*pi)/1000):(4*pi)
for k = 0:n
sigma = (((-1)^k)*sin((2*k+1)*t))/((2*k+1))^2;
e(1, *???*) = sigma; *(%what should I put here instead of (???)?)*
end
r = sum(e(:));
S(1, *???*) = r; *(%what should I put here instead of (???)?)*
end
end
</pre><p>I can't depend on the loop's variable because they are kinda of rational numbers, so how should i store ?</p>Omar Makladhttp://nl.mathworks.com/matlabcentral/profile/authors/8331870-omar-makladtag:nl.mathworks.com,2005:Question/3011582016-08-28T14:56:38Z2016-08-28T18:01:54ZSupport Vectors are wrong in my SVR model<p>I trained an SVR model by fitrsvm. Since I need to get all support vector I have checked the model ouput. Surprisingly, the mdl.SupportVectors have nothing in common with my input mdl.X. Can anyone tell me why.</p><p>Below is my code. sorry the csv files are too larged to be uploaded.</p><pre> input = csvread('sample.csv');
target = csvread('target.csv');
Y = log(target(2,:)+1)';
%Y = log(target(2,:)+1)';
%turbidity = log(target(1,:)+1);
turbidity = target(1,:);
mainComp = 15;
s = load('eigenVector.mat','s');
s = s.s;
v = load('singularValue.mat','v');
v = v.v;</pre><pre class="language-matlab">a = s'*input;
b = inv(v(1:mainComp,1:mainComp))*a(1:mainComp,:);
X = [b;log(turbidity+1)];
mdl = fitrsvm(X',Y,'Standardize',true,'KernelFunction','polynomial','KernelScale','auto','OutlierFraction',0.05);
save mySVMMDL mdl;
yfit = exp(predict(mdl,X'))-1;
</pre>hu yanghttp://nl.mathworks.com/matlabcentral/profile/authors/8607418-hu-yangtag:nl.mathworks.com,2005:Question/3011042016-08-27T19:29:34Z2016-08-28T14:52:53ZGenerating points on flattened sphere<p>hi i am new in matlab I have a flattened sphere x1^2+0.01*x2^2+x3^2=1;
I have code but it does not give exact results.</p><pre class="language-matlab">function A = rand_pick_sphere(n,a,b,X,Y,Z)
% Uniform points in a shell of inner radius a, outer radius b and center at
% (X,Y,Z)
% [x,y,z] = rand_pick_sphere(300,.5,.6); % 300 points in shell between
% r = .5 and r = .6, with center at origin.
if nargin==3
X = 0;
Y = 0;
Z = 0;
end
r1 = (rand(n,1)*(b^3-a^3)+a^3).^(1/3);
phi1 = acos(-1 + 2*rand(n,1));
th1 = 2*pi*rand(n,1);
% Convert to cart.
x = r1.*sin(phi1).*sin(th1) + X
y = r1.*sin(phi1).*cos(th1) + Y
z = r1.*cos(phi1) + Z
A=[x y z];
</pre><p>how can generates points that lies on this sphere
plz help me</p>Ghulam Murtazahttp://nl.mathworks.com/matlabcentral/profile/authors/7957354-ghulam-murtazatag:nl.mathworks.com,2005:Question/3011452016-08-28T12:06:25Z2016-08-28T14:48:30ZHow can I estimate the prestley's evolutionary spectrum in MatLab. <p>I want to estimate the Prestley's Evolutionary Spectrum for non stationary time series using MatLab. I'm wondering whether there is an inbuilt function for this.</p>Samithree Rajapakshahttp://nl.mathworks.com/matlabcentral/profile/authors/8512092-samithree-rajapakshatag:nl.mathworks.com,2005:Question/3011122016-08-27T20:49:42Z2016-08-28T14:25:56Zhi, i want partition largest interval(contain more than element) to 4 interval , and partition the second biggest interval to 3 interval,and partition the third biggest interval to 3 interval, But the rest remains the same.retaining orderofinterval<p>% i have n values z1,z2 , ...,zn this is numerical values . i partition this to seven interval as following and calculate the length for every interval(length for nonzero element), the interval contain more than element from z1,...zn i need partition it to 4 subinterval have same length While retaining the order and the second largest interval partition to 3 subinterval have same length and the third interval partition to 2 subinterval have same length and the remaining interval Remain the same . In the end we get to 13 interval .</p><pre class="language-matlab">n = 50;
z = 1000 * rand(1, n); % Sample data
a=min(z);
b=max(z);
k =7; % such that k is the number of intervals
L= (max(z)-min(z))/k; %such that L is length of each interval
% Here is my solution:
intK = round(k);
uMatrix = [linspace(a, b-L, intK)', linspace(a+L, b, intK)']
for i=1:n
for j=1:k
if (uMatrix(j,1)<=z(i)&z(i)<=uMatrix(j,2))
uMatrix(j,1,i)=z(i);
end
end
end
for i=1:k
temp1=uMatrix(i,:,:);
%whos temp1
temp2 = nonzeros(temp1);
%whos temp2
temp3 = length(temp2);
%w hos temp3
le(i)=temp3;
end
</pre>mohammed hamdyhttp://nl.mathworks.com/matlabcentral/profile/authors/8604732-mohammed-hamdytag:nl.mathworks.com,2005:Question/3011532016-08-28T13:38:19Z2016-08-28T14:21:46ZCompute visible area of partically obscured object of 3D figure<p>I have 2 hemispheres (radius 10.5 and 2.5cm) with slits. In the center is a red cube of 1*1*1cm. I need to calculate the area of the cube that I see from various viewpoints. E.g. when I look from view(90,45) I have to calculate the area of the cube that I can see, but at view (50,60) I can not see the cube, so the area is 0.</p><img src = "/matlabcentral/answers/uploaded_files/58451/Untitled1111111111111111111.png">viet lehttp://nl.mathworks.com/matlabcentral/profile/authors/8352252-viet-letag:nl.mathworks.com,2005:Question/3011522016-08-28T13:17:10Z2016-08-28T14:13:43ZHow to convert time from decimal to HH:MM format in plot?<p>I'm reading from Excel file and in Excel the time is showing in the correct HH:MM format but when I imported it to MATLAB it is showing in decimal. I want to plot a figure with time in the HH:MM format and not decimal. I'm using MATLAB R2013a.</p>Adelinehttp://nl.mathworks.com/matlabcentral/profile/authors/4521533-adelinetag:nl.mathworks.com,2005:Question/3008292016-08-25T06:12:52Z2016-08-28T13:45:25ZWhat is to be done for estimating parameters of model on MATLAB? <p>Especially how <b>Recursive Least Square (RLS) Algorithm</b> can be implemented on uncertain dynamic systems in MATLAB simulink or m-file?</p>Rishikesh Datarhttp://nl.mathworks.com/matlabcentral/profile/authors/6878125-rishikesh-datartag:nl.mathworks.com,2005:Question/3010792016-08-27T12:09:09Z2016-08-28T13:27:24Zsimple linear regression slope calculation <p>i am new to using matlab
i have a trading system written in another language which uses linear regression slope in the algorithm. i thing that is the formula used by metastock originally.
now i am trying to port it into matlab.
Matlab has lots of linear regression models formulas etc. but i cannot decide which formula to use to define it .
suppose i have 10,000x1 rows of data
how can i calculate the slope of linear regression line for last 50 rows.</p><p>edit:
after much reading i am pretty sure the linearregression line formula in trading softwares means ,for last x points of data linearregression(x) is the solution/prediction of next datapoint using linear least squares method. Still i dont know how can i do this. I am very thankful for everyone trying to help. i hope this clarification will help. i am adding a calculated (by some trading software) price,linearregression and linearregressionslope data here.</p>kenan alicihttp://nl.mathworks.com/matlabcentral/profile/authors/7819167-kenan-alici