https://uk.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-04-21T04:31:02Ztag:uk.mathworks.com,2005:Question/4576092019-04-21T02:32:51Z2019-04-21T04:31:02ZWhy is the last simulation value is "0",i can't find where is wrongI write an error probability of anti-podal,however,i found the last simulation value is zero,it means that there is no any error signal in the receiver at that time,but that is possible,and i can't find where do i wrong,can anyone help me?
Code
T_s=10^4;
SNR_dB=[-3 0 3 6 9];
SNR_Watt=10.^(SNR_dB./10);
anti_signal=rand(1,T_s)
%Create the anti-podal signal
for ii=1:length(SNR_dB)
for t=1:T_s
if anti_signal(t)>0.5
anti_signal(t)=1;
else
anti_signal(t)=-1;
end
end
%AWGN noise
noise=(1/sqrt(2)*[randn(1,T_s)+1i*randn(1,T_s)]);
%receive_signal
%10.^(-SNR_dB(ii)/20)*noise is the noise in "x" SNR,like -3dB,0dB,3dB,6dB and 9dB
receive_signal=anti_signal+10.^(-SNR_dB(ii)/20)*noise;
for q=1:T_s
if receive_signal(q)>0
receive_signal(q)=1;
else
receive_signal(q)=-1;
end
end
simulation(ii)=(T_s-sum(anti_signal==receive_signal))/T_s%(Total number-the number which is right)-Total number
end
theoretical=1/2*erfc(sqrt(SNR_Watt));
semilogy(SNR_dB,simulation,SNR_dB,theoretical)
The simulation result is as below,as we can see,the last number is always "0",why?i think there is something wrong in the code,but if this 0 is correct,i can't find a reasonable reason to convince to me
yang-En Hsiaohttps://uk.mathworks.com/matlabcentral/profile/authors/13220840-yang-en-hsiaotag:uk.mathworks.com,2005:Question/4575412019-04-20T14:56:34Z2019-04-21T04:28:17Zregexrep for the neophyteHow to write expression to find and convert financial strings written with comma separator to be able to parse numerically?
Example stirng is something like:
recipients={'John Doe $200, Freddy Flint $132.40 SP19; Mary Lamb $1,423.00-SP19, Joe Blow $1,200'};
which is a list of student scholarship awards entered, unfortunately, free-style in a remarks field in an Excel spreadsheet. I need to parse by student and extract each.
I managed to find/return the location/token of the amounts containing the punctuation, but I'm illiterate with regexp and haven't figured out how to locate the comma then within that substring to remove it.
K>> regexp(recipients,'([$]\d+[,]\d+)','match')
ans =
1×1 cell array
{1×2 cell}
K>> ans{:}
ans =
1×2 cell array
{'$1,423'} {'$1,200'}
K>>
As can be seen, the original text also has "issues" in that the separator between students isn't consistent--it may be a comma or semicolon, not sure what else I'll find as I progress.
For context, this is the next step past the previous Q? of piecing back together disparate databases/spreadsheets...now that I can compare the award to the billing by account, I can find coding or other errors--but need to be able compare the details.
dpbhttps://uk.mathworks.com/matlabcentral/profile/authors/28872-dpbtag:uk.mathworks.com,2005:Question/4575822019-04-20T21:10:51Z2019-04-21T04:18:24ZConverting user input char to an array As part of my university matlab module i was assigned to do an assigment from one of 4 options. I'm on a bit of a road block, part of code is requesting the user to type in 6 numbers for a lottery game, being that this data is recorded as a char i want to convert this to a numerial array (matrix). I have tried the following with no luck.
player_numbers = input ('Please enter your number: ','s');
player_lotto_numbers = str2num(player_numbers);
Mehmet Saglamhttps://uk.mathworks.com/matlabcentral/profile/authors/12224026-mehmet-saglamtag:uk.mathworks.com,2005:Question/4576172019-04-21T04:11:12Z2019-04-21T04:11:12Zphysical layer implementation of ieee 802.11ahwe have to write code for ieee 802.11ah transmitter and receiver with channel modellingThanmai Rachamalluhttps://uk.mathworks.com/matlabcentral/profile/authors/14283070-thanmai-rachamallutag:uk.mathworks.com,2005:Question/4576142019-04-21T03:24:15Z2019-04-21T03:59:38ZFind specific cell in another cellsHi everyone,
Attachment is my file.
I would like to know the locations of this cells containes a specific cell-{21 31 1}
I try to use like below:
Match = {21 31 1};
CorrectMatch = find (cellfun(@(x) isequal (x,Match), condition(1,:)));
but it return 0.
Could any one help me? Ting-Yu Chuehhttps://uk.mathworks.com/matlabcentral/profile/authors/14644923-ting-yu-chuehtag:uk.mathworks.com,2005:Question/3891132018-03-19T00:21:29Z2019-04-21T03:56:37ZWhy the final Validation accuracy appears on the plot different than the accuracy that is calculated by the law of accuracy ?I create and train a simple convolutional neural network for deep learning classification on Matlab, when training finishes, the final validation accuracy that appears on the right side of the plot is different than the accuracy I have gotten from the following law for the validation set
accuracy = sum(predictedLabels == valLabels)/numel(valLabels);Nusaiba Mnayyishttps://uk.mathworks.com/matlabcentral/profile/authors/8515744-nusaiba-mnayyistag:uk.mathworks.com,2005:Question/4576162019-04-21T03:56:12Z2019-04-21T03:56:12ZWhich code of BVP4C replaces the code xSol(t) = simplify(xSol(t)) OR pretty([xSol(t);ySol(t)]) of DSOLVEWhich code of BVP4C replaces the code xSol(t) = simplify(xSol(t)) OR pretty([xSol(t);ySol(t)]) of DSOLVEMINATIhttps://uk.mathworks.com/matlabcentral/profile/authors/10813789-minatitag:uk.mathworks.com,2005:Question/4576122019-04-21T03:18:49Z2019-04-21T03:55:13ZHow to create a function to define a squareHow to create a function to define a squareTOKENhttps://uk.mathworks.com/matlabcentral/profile/authors/8807307-tokentag:uk.mathworks.com,2005:Question/4576152019-04-21T03:43:33Z2019-04-21T03:43:33ZPie Charts- Energy DataHow do I plot pie charts for energy data, for example I have an array that is 83520x1 and I want to plot that against time (which is also in an array that is 83520x1. Fatemah Ebrahimhttps://uk.mathworks.com/matlabcentral/profile/authors/14779500-fatemah-ebrahimtag:uk.mathworks.com,2005:Question/4576052019-04-21T02:08:05Z2019-04-21T03:39:02ZFor an nx3 matrix, filter out the rows with a maximum 3rd column when the first and second are the sameFor a matrix such as:
mat=[0 0 0
1 1 2
1 1 3
1 1 5
2 1 6
3 3 2
3 3 1]
Is there a way to filter this matrix to obtain the following matrix
final=[0 0 0
1 1 5
2 1 6
3 3 2]
Appreciate any help thanksJoseph Maloneyhttps://uk.mathworks.com/matlabcentral/profile/authors/13297175-joseph-maloneytag:uk.mathworks.com,2005:Question/4575442019-04-20T15:36:56Z2019-04-21T03:27:26Z How can I set a starting point in a situation where I have multiple variables?
I am trying to use the fmincon function in Optimtool.
My objective function is objecfun (w, d) and my constraint function is nonlconstr (w, d, g, x).
The number of variable w is 30(w11, w12, w13, w14, w15, w21, ... , w65), the number of d is 30(d11, d12, d13, d14, d15, d21, ... , d65), g is 6(g1, g2, g3, g4, g5, g6), and x is 3(x1, x2, x3).
I entered a value within the constraint range of each variable at the starting point, but an error of 'x0: matched dimension of the concatenated matrix' occurred.
How do I set the starting point in optimtool?
I look forward to your reply. Thank you.TaeWan Kimhttps://uk.mathworks.com/matlabcentral/profile/authors/15336820-taewan-kimtag:uk.mathworks.com,2005:Question/4576132019-04-21T03:19:05Z2019-04-21T03:19:05Ztransfer shallow network layer to new shallow netI am trying to take a layer(s) from a shallow network and use them in a new network. see below
%
% define net layers
%
autoenc = feedforwardnet([nn1_try], 'trainlm');
%
% training parameters for autoencoder
%
autoenc.trainParam.epochs = 100; % Maximum number of epochs to train
autoenc.trainParam.goal = 0; % Performance goal
autoenc.trainParam.max_fail = 100; % Maximum validation failures
autoenc.trainParam.min_grad = 1e-6; % Minimum performance gradient
autoenc.trainParam.mu = 0.00001; % initial mu
autoenc.trainParam.mu_dec = 0.3; % mu decrease factor
autoenc.trainParam.mu_inc = 3.0; % mu increase factor
autoenc.trainParam.show = 1; % Epochs between displays (NaN for no displays)
autoenc.trainParam.showCommandLine = false; % Generate command-line output
autoenc.trainParam.showWindow = true; % Show training GUI
autoenc.trainParam.time = 100; % Maximum time to train in seconds
%
% train first hidden layer on autoencoding
%
autoenc = train(autoenc,Xtrain',Xtrain',[],[],err_weight,'useParallel','yes');
%
% training parameters for deeper feedforward network
%
net = feedforwardnet([nn1_try,nn2_try], 'trainlm');
%
% now main network parameters
%
net.trainParam.epochs = 1000; % Maximum number of epochs to train
net.trainParam.goal = 0; % Performance goal
net.trainParam.max_fail = 100; % Maximum validation failures
net.trainParam.min_grad = 1e-6; % Minimum performance gradient
net.trainParam.mu = 0.00001; % initial mu
net.trainParam.mu_dec = 0.3; % mu decrease factor
net.trainParam.mu_inc = 3.0; % mu increase factor
net.trainParam.show = 1; % Epochs between displays (NaN for no displays)
net.trainParam.showCommandLine = false; % Generate command-line output
net.trainParam.showWindow = true; % Show training GUI
net.trainParam.time = 100; % Maximum time to train in seconds
%
% train network
%
net = train(net, Xtrain', Ytrain,[],[],err_weight,'useParallel','yes');
%
% establish performance against entire dataset
%
y = net(Xtrain');
y_estimate = y*vbase; % invert normalization to get actual delta-V estimate
y_true = Ytrain*vbase; % invert normalization to get true delta-Vs
This code works, but how do I transfer the autoenc's first layer to initialize net's initial layer?Leonard Dean Vancehttps://uk.mathworks.com/matlabcentral/profile/authors/15311511-leonard-dean-vancetag:uk.mathworks.com,2005:Question/4576112019-04-21T03:01:00Z2019-04-21T03:09:48Zhow can i ask the user for 2*2 matrixI am trying to let the user enter input in matrix form
matr = input ('enter values in matrix form [a,b; c,d]');
but how can I make sure that the user input 2 columns only but whatver rows. I am new to manipulating array and matrix.mat geekhttps://uk.mathworks.com/matlabcentral/profile/authors/9600941-mat-geektag:uk.mathworks.com,2005:Question/4576102019-04-21T02:47:54Z2019-04-21T02:47:54ZHow can I recognize shapes of simple geometrical objects using optimization toolsHere is the sample code to recognize a circle, looks like I need to create different functions to define a square, rectangle and a triangle first if I want recognize them. Can someone help me with it? Thanks.
clc
clear
M0=zeros(1024,1024); % Background of zeros
x=1:1024;
y=1:1024;
[X,Y]=meshgrid(x,y); % grid of pixel positions
for in=11
A=double(imread([num2str(in,'%4.3d'),'.jpg']))/255; % Load image and scale to 1
M=@(p) M0+double((X-p(1)).^2+(Y-p(2)).^2<(p(3))^2); % define your teplate
% You may need a separate funtion file
fun=@(p) sum(sum(abs(A-M(p)).^2)); % The objective funtion to minimize
% find the avergae center position and ditribution of the nonzero
% pixels in image
pos=find(A>0);
x0=mean(X(pos));
y0=mean(Y(pos));
d=(range(X(pos))+range(Y(pos)))/2;
trl=[x0 y0 d/2]; % The trial solution % number of parameters depend on the shape
lb=[0 0 0];% lower bounds of the prameters
ub=[1024 1024 512];% upper bounds of the prameters
% Optimization process
%You dont have to change the below lines
opts=optimoptions('ga');
opts.InitialPopulationMatrix=trl;
opts.Display='iter';
[sol,fval]=ga(fun,length(trl),[],[],[],[],lb,ub,[],opts);
if fval<100
'circle'
else
'unknown'
end
figure(1)
clf
surf(M(sol),'linestyle','none')
view(2)
daspect([1 1 1])
figure(2)
clf
surf(A,'linestyle','none')
view(2)
daspect([1 1 1])
end
TOKENhttps://uk.mathworks.com/matlabcentral/profile/authors/8807307-tokentag:uk.mathworks.com,2005:Question/4576082019-04-21T02:29:45Z2019-04-21T02:29:45Z¿Como puedo traspasar esta serie a una funcion?8fac = 1;
n=input('favor ingresar cantidadd e terminos: ');
x=input('Ingresar el valor de x: ');
s=x;
for i=2:n
fac = fac * ((i*2)-1);
if(mod(i,2)== 0)
s=1 - double((x^(i*2))/fac
else
s=1 + double((x^(i*2))/fac
end
end
disp('el valor de Cos(x) se aproxima a: ');
Es una serie del cos(x)Thomas Bustoshttps://uk.mathworks.com/matlabcentral/profile/authors/12620250-thomas-bustostag:uk.mathworks.com,2005:Question/4576072019-04-21T02:29:13Z2019-04-21T02:29:13ZHow can I present a 3D particle with cube mesh? Hi,
I want to draw a spherical particle whick is made of small cubes in MALTAB. I can define the coordinate of each cube inside the particle, however, do not know how to show (or define) each mesh as a cube. Thank you in advance for your help.
Masoud Shabani nezhad navroodhttps://uk.mathworks.com/matlabcentral/profile/authors/10447316-masoud-shabani-nezhad-navroodtag:uk.mathworks.com,2005:Question/4575742019-04-20T20:13:56Z2019-04-21T02:23:32ZHow to delete a column from a TimeSeries?Hello,
I would like to know how to delete a column from a TimeSeries.
I need to plot two curves in the same figure but different y-axis. First: time vs temperature; second: time vs level.
I got the temperature from a TimeSeries matrix called MyTimeSeries, whereas the level is in a datetime array. Unfortunatelly, when I try the code below, an error* appears in the add axis function.
plot(MyTimeSeries.Time, MyTimeSeries.Data(:,1)); hold on
addaxis(Time,Level);
So i use the follow code. However, it also plots data (:,2), (:,3), etc, and I need only Data(:,1). That's why I need to delete the other columns.
plot(MyTimeSeries); hold on
addaxis(Time,Level);
Well, I had tried to convert MyTimeSeries.Time and MyTimeSeries.Data to datetime values, but when I do it, the matrix is very strange, with strange numbers instead of time.
I also tried to convert Time and Level to a TimeSeries format, but when I do it, another error** appears, since some values in "Level" are N/A (because this is the way my controller works, it applies N/A for some conditions).
MyTimeSeries.Time format: '29-Mar-2019 09:40:15'
================================================================================
*Error:
Error using aa_splot (line 24)
Data inputs must match the axis configuration. A numeric axis must have numeric
data inputs or data inputs which can be converted to double.
Error in addaxis (line 135)
hplts = aa_splot(varargin{:});
**Other error:
Error using timeseries.tsChkTime (line 572)
Time vector must contain only finite values.
Error in timeseries/init (line 286)
time = timeseries.tsChkTime(time);
Error in timeseries (line 343)
this = init(this,varargin{:});Marlon Saveri Silvahttps://uk.mathworks.com/matlabcentral/profile/authors/6314509-marlon-saveri-silvatag:uk.mathworks.com,2005:Question/4576062019-04-21T02:21:46Z2019-04-21T02:22:29Zdifferent font sizes for y labelsHello,
I want to have different font sizes for y-labels. for example in this simple plot, I want to have -2 and 2 in y-axis in font 16 and the rest in font 12:
x = -1:0.01:1;
y = 3*asin(x);
plot(x,y)
set(gca,'Ytick',[-4, -2, 0, 2, 4])Hamidhttps://uk.mathworks.com/matlabcentral/profile/authors/8477485-hamidtag:uk.mathworks.com,2005:Question/4573612019-04-19T12:04:10Z2019-04-21T02:08:56ZHow can I install mosek in matlab for free?How can I install mosek in matlab for free?Karry Mahttps://uk.mathworks.com/matlabcentral/profile/authors/15283432-karry-matag:uk.mathworks.com,2005:Question/4576042019-04-21T02:07:13Z2019-04-21T02:07:13ZHow can I use 'yalmip' to solve the Quadratic stability range of uncertain model in control system?How can I solve the value '0.6812' by using 'yalmip' or 'LMI'?I would appreciate it if you could give me an example.Karry Mahttps://uk.mathworks.com/matlabcentral/profile/authors/15283432-karry-matag:uk.mathworks.com,2005:Question/4576032019-04-21T01:58:50Z2019-04-21T01:58:50Zvariable nonlinear spring & damperI could not find 'variable nonlinear spring or damper' in the Simulink component. Is there any way to chane fixed value nonlinear spring/damper to variable nonlinear spring /damper? harsh vardhanhttps://uk.mathworks.com/matlabcentral/profile/authors/12263913-harsh-vardhantag:uk.mathworks.com,2005:Question/4573772019-04-19T13:35:12Z2019-04-21T01:56:17ZHow to check Excel sheet data of one with Excel sheet data of another on matlab and print the output on another Excel sheetSo,
I'm reading a list of flights data from an excel sheet called plot:
journeys = readtable('plot.xlsx');
And I have an ATS route givwen by lat10 and lon10:
lat10 = [12.9933,19.0852]; lon10 = [80.1705,72.8752];
I'm reading the flight data and selecting them based on groups (flight numbers) of flights that have 80% of their data within the ats route:
[x10, y10]= mfwdtran(mstruct,lat10,lon10);
X = [x10,fliplr(x10)];
Y = [y10,fliplr(y10)-d];
%Y = [y10,fliplr(y10)-d];
plot(x10,y10,'-','color','m');%plotting ats
hold on;
plot(x10,y10-d,'-','color','m');%only for 2nd and 3rd batch
%plot(x10-d,y10,'-','color','m');%only for first batch
hold on;
%selecting flights--------------
[journeys.x, journeys.y] = mfwdtran(mstruct, journeys.latitude, journeys.longitude); %transform the flights latitude and longitude
in = inpolygon(journeys.x, journeys.y, X, Y);
[groupid, flights] = findgroups(journeys.flight); %assign unique id to each flight and apply to rows of the table
inratio = splitapply(@(in)nnz(in)/numel(in), in, groupid); %ratio of points in polygon to points in flight
selectedflights = flights(inratio >= .8); %for flights that have 70% of their journey in the polygon
% isallin = splitapply(@all, in, groupid); %are ALL points of the flight in the polygon? logical output
% selectedflights = flights(isallin); %list of flights where all points are in the polygon
selectedjourneys = journeys(ismember(journeys.flight, selectedflights), :); %portion of the table with only the selected flights.
%selecting flights--------------
Now, I have a list of ATS routes in an excel sheet called ATS and I want to compare each flight data with each route that they correspond to. If a flight has 80% of its data within the route I want an excel sheet called Match to have the flight number and the ATS route it matches with.
I'm stuck with this problem from a long time now... kindly help please...
I have attached the excel sheets here.harman bhavejahttps://uk.mathworks.com/matlabcentral/profile/authors/15243328-harman-bhavejatag:uk.mathworks.com,2005:Question/4576022019-04-21T01:51:10Z2019-04-21T01:51:10Zhow do create test label?hai...i tried to run the kNN matlab code;
function [acc,score]=kNN(train,trainlabel,test,testlabel,k)
%train,trainlabel,test,testlabel
%return "accuravy rate"
N_tr=size(train,1);
N_ts=size(test,1);
Answer=zeros(N_ts,1);
for i=1:N_ts
% calc distance^2 between all train data and a test data
Temp=train-ones(N_tr,1)*test(i,:);
Distance2=sum(Temp.^2,2);
% [MIN I]=min(Distance2);
% Answer(i)=trainlabel(I);
neibors=sortrows([Distance2,trainlabel],1);
Answer(i)=mode(neibors(1:min(k,size(neibors,1)),2));
end
%[ANS testlabel];
acc=(1-nnz(Answer-testlabel)/N_ts)*100;
score=(Answer-testlabel==0);
how do i create the train label?(please see my 'DATA.txt' attachment).
my DATA.txt contains 5 X 10 matrix. each row represent class1~class5. EDWARD IJAU PELIAS POGhttps://uk.mathworks.com/matlabcentral/profile/authors/15025257-edward-ijau-pelias-pogtag:uk.mathworks.com,2005:Question/4573692019-04-19T13:13:16Z2019-04-21T01:47:37ZHow to draw equally sized squaresHi,
I draw a circle of radius 1, and I want to draw eqaully sized squares in the background of the circle. Kindly some one help,
r = 1. 0;
th = linspace(0,2*pi) ;
x = r*cos(th) ;
y = r*sin(th) ;
patch(x,y,rand(1,3)) ; % I am using random color in patch here.
axis equal
Now I want draw 10x10 squares as a background to the circle (the dia of each square is (2*r/10)). Mekala balajihttps://uk.mathworks.com/matlabcentral/profile/authors/5786945-mekala-balajitag:uk.mathworks.com,2005:Question/4575812019-04-20T21:03:20Z2019-04-21T01:44:14ZCalling option from menu functionThe code has main menu based on ATM macine. 1-Get cash. 2-Get Balance. 3-Quit % if user choose option 1
Mainmenu= menu('Main Menu','1-Get Cash','2-Get Balance','3-Quit');
if Mainmenu ==1
In Get Cash, Another menu that the user have to choose how much to withdraw
GetCashM= menu('Withdrawal amount','20$','40$','100$','200$');
, and after that, another menu to prompt the user to select 1- checking, 2- savings,
Acct= menu('From which account','checking','Saving');
and disp how many 20 bills were dispansed that is after verifying if there are enough funds in the selected account. And when option 1 or 2 are processed, the main menu will show again. I got that done. But, If option 3- quit selected, display New checking Balance and New Saving Balance. But how can I subtract the withdraw amount from checking savings account since menu option are string I think. Even if I called it it would be 1 or 2 or 3 or 4 respectivly to withdraw amount menu.
(ex)
Sbal = 100;
if the user withdrew 20$ from Sbal . "in option 1 from whidraw amount "
"second iteration."
if MainMenu ==. 3 % if the user choose option quit after proseccing whidraw amount
NewSavBal = GetCashMenu - SBal;
but that did not do it since values inside menu were string.
Keep in mind that
If the user closes the menu rather than making a selection, warning message should bedisplayed and the user given 2 more chances to make a selection from that menu. If they still close the menu on the 3rd attempt, an error message should be displayed that says the program has been terminated.mat geekhttps://uk.mathworks.com/matlabcentral/profile/authors/9600941-mat-geektag:uk.mathworks.com,2005:Question/2806152016-04-23T18:42:53Z2019-04-21T01:27:30ZHow can I find poles and zeros of transfer function matrix ?I have a matrix of transfer funtion of MIMO system and i have to find its poles and zerosMuhammad Waleedhttps://uk.mathworks.com/matlabcentral/profile/authors/8085997-muhammad-waleedtag:uk.mathworks.com,2005:Question/4576002019-04-21T00:45:09Z2019-04-21T01:23:13ZCan you make a section of a GUI jump back to another?I'm currently making a GUI that essentially filters data based on different parameters and then graphs the answer.
This group of radio buttons changes the filtering parameters and thus changes the answer you get.
I was wondering if you can use the MATLAB GUI syntax to help aid in this process. Here's the code for the radiobutton callback. I want it to automatically branch back to the filter function part of the GUI without having the copy and paste the code again that makes it display. Is there any function/command that will essentially say "go back to this part of the GUI code"?
% --- Executes when selected object is changed in waveselection.
function waveselection_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in waveselection
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Changes the
switch(get(eventdata.NewValue,'Tag'));
case 'deltawave'
handles.filterFreqs = [1 5];
case 'alphawave'
handles.filterFreqs = [7 16];
case 'betawave'
handles.filterFreqs = [14 41];
case 'gammawave'
handles.filterFreqs = [29 101];
end
guidata(hObject, handles);%Updates handles structure
Thank you greatly for any and all help!Blair Armstronghttps://uk.mathworks.com/matlabcentral/profile/authors/13338781-blair-armstrongtag:uk.mathworks.com,2005:Question/4576012019-04-21T01:08:59Z2019-04-21T01:20:42ZCurve fitting (curve fitting tool)Is there a way to do multiple curve fittings on same window?Chanaka Navarathnahttps://uk.mathworks.com/matlabcentral/profile/authors/14638173-chanaka-navarathnatag:uk.mathworks.com,2005:Question/4575942019-04-20T22:46:27Z2019-04-21T00:31:47ZHow can I prevent MATLAB from changing certain initial conditions using ode15s?I am trying to solve a DAE system using ode15s.
Due to the structure of ode15s I have to input initial conditions for all variables, however using degrees of freedom analysis on the problem only the differential equations need initial conditions. Due to that, I obtained all of the initial conditions in another MATLAB script and input them in ode15s. As MATLAB converges, however, it's changing the initial conditions of the 2 differential equations (which are the only ones that need to remain constant, in order to solve the required physical problem).
Is there a way to ensure that certain initial conditions remain unchanged?
Is there a way to add inequality constraints on the outputs of ode15s?
Thank you.Georgios Pasiashttps://uk.mathworks.com/matlabcentral/profile/authors/11127140-georgios-pasiastag:uk.mathworks.com,2005:Question/3930262018-04-06T07:55:30Z2019-04-21T00:18:37ZHow to Code for "Artificial Flora (AF) Optimization Algorithm?"The *Artificial Flora (AF) Optimization Algorithm* has been proposed recently.
The authors wrote that they use MATLAB, but they did not publish the code.
Knowing that if there is an open access method that can code this method with MATLAB, it will make a big contribution to science.
It is very important to explicitly publish Matlab codes for the development of the method and the experimental results.
Algorithm of the method proposed by the authors:
<<http://www.mdpi.com/applsci/applsci-08-00329/article_deploy/html/images/applsci-08-00329-g002.png>>
You can access the paper and method algorithm in the following address.
<http://www.mdpi.com/2076-3417/8/3/329>
If there is anything that can help in the coding, I'm very happy. I am ready to make the contribution for coding the method with MATLAB.
Thank you very much. Yasin KAYAhttps://uk.mathworks.com/matlabcentral/profile/authors/10058776-yasin-kayatag:uk.mathworks.com,2005:Question/4575972019-04-20T23:10:47Z2019-04-21T00:12:08ZHow to use polyfit to get the difference out of two functions?Hi
I have two datasets (X,Y). For every value of Y that corresponds to a value of X.
I am thinking of applying a polyfit command to get the best curve fitting for the data, and as a result I will come up with a function (slope+intercept).
How do I find the difference between those two functions? What command do I apply to subtract Function A from Function B?
Stelios Fanourakishttps://uk.mathworks.com/matlabcentral/profile/authors/10865530-stelios-fanourakistag:uk.mathworks.com,2005:Question/4575882019-04-20T21:48:48Z2019-04-21T00:04:03ZHow to update nodes with the calculated distance weight ? without using Dijkstra functionI need to code for dijkstra algorithm (without using matlab built in function), can anyone please tell me how to code it ? further how to update weights of the visited nodes ?
Fariha Komalhttps://uk.mathworks.com/matlabcentral/profile/authors/14913336-fariha-komaltag:uk.mathworks.com,2005:Question/4575892019-04-20T21:56:28Z2019-04-21T00:00:51Zellipsoid with surf command?obviously there are some complex numbers because of root in this code, but how can we plot ellipsoid using functions in the library?
[x,y] = meshgrid(1:0.5:10,1:20);
z = sqrt((3-x.^2-y.^2)/4);
surf(x,y,z)Kuatra Patilhttps://uk.mathworks.com/matlabcentral/profile/authors/15291254-kuatra-patiltag:uk.mathworks.com,2005:Question/4575992019-04-20T23:47:43Z2019-04-21T00:00:31ZRadius of Curvature ArrayThe code generates radius of curvatures for three points(coordinates x1,y1 x2,y2 and x3,y3. However, i have a set of coordinates (77) in all, and I am trying to rewrite the code to loop through the coordinates and generate a radius of curvature for every three points within the set of 77, and store the result in another variable say R. I have not been able to do this and I need urgent help: See the radius of curvature code below that generates when radius of curvature for 3 points.
function lambda=mycurvature(xinput, yinput)
global xstar ystar;
xstar=xinput;ystar=yinput;
alpha=atan2(ystar(2)-ystar(1),xstar(2)-xstar(1))-atan2(ystar(3)-ystar(2),xstar(3)-xstar(2));
if abs(alpha)<0.002; %set the curvature to 0 if the points are aligned
R=inf; lambda=0;
%plot(xstar,ystar,'-r',xstar,ystar,'*b','linewidth',2,'markersize',10);
else
initialguess = [1; 1; 1]; % Make a starting guess at the solution
options=optimset('Display','none'); % Option to display output
res = fsolve(@userfun,initialguess,options); % Call optimizer
x0=res(1);y0=res(2);R=res(3); %x-coord of center; y-coord of center; radius of curvature
lambda=1/R; %curvature
%t=0:0.01:2*pi;xx=x0+R*cos(t);yy=y0+R*sin(t);
%plot(xx,yy,'-r',xstar,ystar,'*b','linewidth',2,'markersize',10);
end
%str=sprintf('radius=%6.3f, curvature=%6.3f',R,lambda);
%title(str, 'fontsize', 14);xlabel('x'),ylabel('y');
%axis equal;
function F = userfun(vars)
global xstar ystar;
F = [...
(xstar(1)-vars(1))^2+(ystar(1)-vars(2))^2-(vars(3))^2; ...
(xstar(2)-vars(1))^2+(ystar(2)-vars(2))^2-(vars(3))^2; ...
(xstar(3)-vars(1))^2+(ystar(3)-vars(2))^2-(vars(3))^2; ...
];
xinput are the array of x coordinates for the three points, yinput are the array of y coordinates for the 3 points.
What i am doing that is not working is
x = [array of my x-coordinates of my 77 points]; y =[array of my y-coordinates of my 77 points]
for i = 1:3:length(x)-1
xinput = x(i), x(i+1), x(i+2)
yinput = y(i), y(i+1), y(i+2)
and then removed the function at the first line of code for the radius of curvature code above. This did not work. What am I doing wrong? Please help.Jide Williamshttps://uk.mathworks.com/matlabcentral/profile/authors/13528121-jide-williamstag:uk.mathworks.com,2005:Question/4575912019-04-20T22:06:54Z2019-04-20T23:59:42ZHow can i coding binary array using RNA codingHello every one
pls if any one know .
How can i coding binary array using RNA codingRNA coding?
ammar mohammedhttps://uk.mathworks.com/matlabcentral/profile/authors/14858931-ammar-mohammedtag:uk.mathworks.com,2005:Question/4575922019-04-20T22:15:40Z2019-04-20T23:58:52ZHow canI i generate chaotic map 3 Dimension and convert it into hexadecimal ?Hello every one
I want code of How can I generate chaotic map 3 Dimension and convert it into hexadecimal ?
pls If anyone can help me
Aliammar mohammedhttps://uk.mathworks.com/matlabcentral/profile/authors/14858931-ammar-mohammedtag:uk.mathworks.com,2005:Question/4575962019-04-20T22:51:51Z2019-04-20T23:56:06ZWrite a MATLAB® Write a MATLAB® script to graph the variable (𝒚) vs. the variable (𝒙). . [2 Pts] 𝒚 = 𝟎. 𝟒 √𝟏. 𝟖 𝒙 for 𝟎 ≤ 𝒙 ≤ 𝟑𝟓Pamela Aquinohttps://uk.mathworks.com/matlabcentral/profile/authors/15290678-pamela-aquinotag:uk.mathworks.com,2005:Question/4575982019-04-20T23:38:52Z2019-04-20T23:55:09ZWon't Plot in 3D%-----------------------------------------------------------------
%.... Name:Ariana Garcia
%.... Date:April 21,2017
%.... Project:CP4
%.... Recitation Section:Mon
%-----------------------------------------------------------------
%-----------------------------------------------------------------
%....
%.... Truss Analysis
%....
%-----------------------------------------------------------------
%***** READ THIS *****
% You must modify this code so that it works for any truss that the user
% wishes to analyze, whether 2-D or 3-D.
% Therefore, after your code is modified, all trusses should be assumed as
% 3-D Space Trusses.
% For 2-D planar trusses, the z-coordinate of each joint should be zero
% and the e3 magnitude of all external forces and reactions should be zero.
clear; clc;
% Print Banner to command window
fprintf('%s\n','*-----------------------------------------------*')
fprintf('%s\n','| CEE210 Statics, Computing Project 4 |')
fprintf('%s\n','| Original by Amie Baisley, 11.01.2013 |')
fprintf('%s\n','| Modified by Chris A. Lawrence, 04.02.2016 |')
fprintf('%s\n','*-----------------------------------------------*')
fprintf('\n\n\n')
%% ***********************************************************************
% Create a separate m file that contains several different truss input
% sections, any one of which can be copied and pasted into the truss
% analysis program, without having to modify the rest of the code.
% The file should be named CEE210_NNN_Truss_Inputs.m where NNN is your
% initials.
% The input file should contain every truss that was used to test your
% truss analysis code and must be submitted with your project.
% ************************************************************************
%% **********************************************************************
% 3D Space Trust from CP3
% Units used:
LUnit = 'ft'; % Length = ft or m
FUnit = 'lb'; % Force = lb or kip or N or kN
%.. Input problem data
nNodes = 7; % Number of nodes (pin joints) in the truss
nMembers = 15; % Number of members
nReactions = 3; % Number of force vector reactions
nLoads = 1; % Number of externally applied loads
nDim = 3; % Dimensions 2=2D, 3=3D
% *** Once your code is modified and tested, nDim must always equal 3 and
% the variable nDim cannot be used in your code.
nDOF = nDim * nNodes; % Number of degrees of freedom
tol = 1.e-8; % Remainder tolerance on norm of residual force
%.... Input node coordinates
Node(1,:) = [2,-3,0];
Node(2,:) = [2,3,0];
Node(3,:) = [-4,3,0];
Node(4,:) = [1,-1.5,6];
Node(5,:) = [1,1.5,6];
Node(6,:) = [-2,1.5,6];
Node(7,:) =[0,0,12];
%.... Finish inputting nodes
%.... Input member connections
Member(1,:) = [1,2];
Member(2,:) = [2,3];
Member(3,:) = [3,4];
Member(4,:) = [3,5];
Member(5,:) = [3,6];
Member(6,:) = [1,3];
Member(7,:) = [2,5];
Member(8,:) = [2,4];
Member(9,:) = [1,4];
Member(10,:) = [4,7];
Member(11,:) = [5,7];
Member(12,:) = [6,7];
Member(13,:) = [5,6];
Member(14,:) = [4,5];
Member(15,:) = [5,7];
%.... Finish inputting member connections
% Input support reactions
%.. First input is the node number
%.. Second input is resistance in the e1 direction
%.. Third input is resistance in the e2 direction
%.. Fourth input is resistance in the e3 direction (zero for 2-D trusses)
%*** 1 for resistance in that direction, 0 for no resistance ***
Reaction(1,:) = [1, 1,1,0]; % Pin at Node 1
Reaction(2,:) = [2, 0,1,0]; % Roller at Node 5
Reaction(3,:) = [3, 1,1,1];
% Input externallly applied loads
%.. First input is the node number, remaining inputs are the magnitude of
%.. the force in the e1, e2 and e3 directions, respectively.
Load(1,:) = [5, 0, 200, -500]; % 1000 lb load at Node 2
% End of Input Section for CP3 Space Trust.......
%*****************************************************************************************
%% Compute the unit vector (direction) for every member
PosVec = zeros(nMembers, 3); %Initialize Position Vector matrix
UnVec = zeros(nMembers, 3); %Initialize Unit Vector matrix
OppUnVec = zeros(nMembers, 3); %Initialize opposite direction matrix
for i = 1 : nMembers
SN = Member(i,1);
EN = Member(i,2);
% ***** This section is where your CP3 code should go. *****
PosVec(i,:) = Node(EN,:)- Node(SN,:); % postion vector
length=norm(PosVec(i,:));
UnVec(i,:)=PosVec(i,:)./norm(PosVec(i,:));
OppUnVec(i,:) = -PosVec(i,:)./norm(PosVec(i,:));
end
%% The coefficient matrix, C, contains the unit vectors (direction vectors)
% for each member force associated with each node. The unit vectors are
% then separated into e1, e2, e3 components and placed in separate rows.
% Therefore, each node has 2 rows (for 2-D) or 3 rows (for 3-D) associated
% with it; one for each of the e1, e2, e3 components.
% This corresponds with the Degrees of Freedom, nDOF, which is 2*nNodes
% for 2-D or 3*nNodes for 3-D.
% So the coefficient matrix has 2 or 3 rows for each node and one column
% for each member force.
C = zeros(3*nNodes, nMembers); %Initialize coefficient matrix
% Loop through all nodes, create the vector force equation for that node
% and store it in the proper row of the coefficient matrix, C.
for i = 1 : nNodes
for j = 1 : nMembers
SN = Member(j,1);
EN = Member(j,2);
if (SN == i) % If member j starts at node i
C(3*i-1, j) = UnVec(j,1);
C(3*i, j) = UnVec(j,2);
C(3*i, j) = UnVec(j,3);
elseif (EN == i) % If member j ends at node i
C(3*i-1, j) = OppUnVec(j,1);
C(3*i, j) = OppUnVec(j,2);
C(3*i, j) = OppUnVec(j,3);
end % if SN
end % for nMembers
end % for nNodes
%% The External Force matrix, F, contains the magnitude of all externally
% applied loads, (input as e1, e2, e3 components), stored in the
% proper rows to corespond with the node it is applied at.
% Therefore, the F matrix has 2 or 3 rows for each node and one column.
F = zeros(3*nNodes, 1); %Initialize External Force matrix
% Loop through all externally applied loads and place each component of the
% load (e1, e2, e3) in the proper rows in the external load matrix, F.
for i = 1 : nLoads
j = Load(i,1); % Which node, j is the load i on
F(3*j-1) = Load(i,2);
F(3*j) = Load(i,3);
F(3*j) = Load(i,4);
end % for i,nLoads
%% The Restraint matrix, Crest, contains the unit vectors (directions)
% for each member force associated with those nodes that are restrained by
% external supports.
% The Crest matrix has one row for each reaction component and one column
% for each member.
%.... Loop through all nodes and determine if there is a reaction at that
%.... node and seperate the reaction node equations from the force load
%.... equations.
nReaction = 1; %Used to count the number of reaction equations
%.... The nReactionEquation vector determines if a row should be put in the
%.... Crest matrix or the Cfree matrix
nReactionEquation = zeros(1, 3*nNodes);
for (j = 1 : nReactions)
for (i = 1 : nNodes)
if (Reaction(j,1) == i)
if (Reaction(j,2) == 1)
Crest(nReaction,:) = C(3*i-1,:);
nReactionEquation(3*i-1) = 1;
% If nReactionEquation is 1 it should be in the Crest
% matrix and not the Cfree matrix.
nReaction = nReaction+1;
end
if (Reaction(j,3) == 1)
Crest(nReaction,:) = C(3*i,:);
nReactionEquation(3*i) = 1;
% If nReactionEquation is 1 it should be in the Crest
% matrix and not the Cfree matrix.
nReaction = nReaction+1;
end
end
end
end
nForce = 1; %Used to count the number of Cfree equations
for (i = 1 : 3*nNodes)
if (nReactionEquation(i) == 1)
else
Cfree(nForce,:) = C(i,:);
Ffree(nForce) = F(i);
nForce = nForce + 1;
end
end
%% Solve first for the member forces and then solve for the support
% reactions.
% All of the values in the Cfree and Ffree matrices are known so you can
% now solve for the T matrix, which is the tension force in each member.
T = -(Cfree)\(Ffree)' ; % finish this equation
% Since all values in the Crest and T matrices are now known, you can solve
% for the support reactions.
Reactions = -Crest*T ; % finish this equation
% Calculate the residual to find the amount of error and ensure that
% equilibrium was satisfied.
Residual1 = (Cfree * T + Ffree');
Residual2 = (Crest * T + Reactions);
Res = norm(Residual1) + norm(Residual2);
% Create the support reaction matrix.
nReaction = 1;
for (i = 1 : nNodes)
if (nReactionEquation(3*i-1) == 1)
SupportReaction(i,1) = i;
SupportReaction(i,3) = Reactions(nReaction);
nReaction = nReaction+1;
end
if (nReactionEquation(3*i-2) == 1)
SupportReaction(i,1) = i;
SupportReaction(i,2) = Reactions(nReaction);
nReaction = nReaction+1;
end
if (nReactionEquation(3*i) == 1)
SupportReaction(i,1) = i;
SupportReaction(i,4) = Reactions(nReaction);
nReaction = nReaction+1;
end
end
%% Create output for command window
fprintf('%s\n' , '----------------------------------------')
fprintf('%s\n' , '------------- Truss --------------')
fprintf('%s\n' , '----------------------------------------')
fprintf('%s',' Node Coordinates (', LUnit, ')')
fprintf ('\n')
for i = 1 : nNodes
fprintf('%s%4i%8.3f%8.3f%8.3f\n',' Node: ', i, Node(i,:)')
end % for i, nNodes
fprintf ('\n')
fprintf('%s',' Member Forces (', FUnit, ')')
fprintf ('\n')
for i = 1 : nMembers
fprintf('%s%4i%12.3f\n',' Member Force: ',i, T(i))
end % for i, nMembers
fprintf ('\n')
for i = 1 : nReactions
for j = 1 : nNodes
if (Reaction(i,1) == j)
fprintf('%s%s%s%4i%12.3f%12.3f%12.3f\n',...
' Support Reaction (',FUnit,') at Node ',...
SupportReaction(j,:))
fprintf ('\n')
end % if Reaction
end % for j, nNodes
end % for i, nReactions
fprintf('\n%s%8.3f\n',' Residual Error: ', Res)
fprintf('\n\n\n')
%% Create the plot............................................
% Once your code is modified the plot will be 3-D and so you may need the
% "Rotate 3D" command to view the truss figure properly.
%.. Plot members with color indicating tension or compression
Marker = ceil(25 / sqrt(nNodes));
fig1 = figure(1); clf; grid on; axis equal;
hold on;
xlabel(cat(2, 'X (',LUnit,')' ));
ylabel(cat(2, 'Y (',LUnit,')' ));
zlabel(cat(2, 'Y (',LUnit,')' ));
title('Truss Analysis');
small = max(T)*tol;
for m = 1 : nMembers
if (T(m) < -small)
MColor = 'b'; % Color compression members blue
elseif (T(m) > small)
MColor = 'r'; % Color tension members red
else
MColor = 'k'; % Color "zero force members" black
end % if T
SN = Member(m,1);
EN = Member(m,2);
X = [Node(SN,1); Node(EN,1)];
Y = [Node(SN,2); Node(EN,2)];
Z = [Node(SN,3); Node(EN,3)];
if nDim== 3
p = plot3(X,Y,Z);
end
if nDim== 2
p = plot(X,Y);
end
set(p, 'Color', MColor, 'LineWidth', 6/nDim);
end % for m, nMembers
%.. Plot external reaction forces
Rlength = 0.1 * max(max(Node)); % establish size of line
e = [ 1, 0, 0 ; 0, 1, 0 ; 0, 0, 1];
for i = 1 : nReactions
for j = 1 : nNodes
if (Reaction(i,1) == j)
for k = 1 : 2
if(Reaction(i, k+1) == 1)
xR(1,:) = Node(j,:);
xR(2,:) = Node(j,:) - Rlength * e(k, 1:nDim);
xR(3,:) = Node(j,:) - Rlength * e(k, 1:nDim);
if nDim== 2
p = plot(xR(:,1),xR(:,2));
end
if nDim== 3
p = plot3(xR(:,1),xR(:,2),xR(3,:));
end
set(p,'Color','g','LineWidth',8/nDim);
end % if Reaction == 1
end % for k
end % if Reaction == j
end % for j, nNodes
end % for i, nReactions
%.. Plot loads
Llength = 0.1 * max(max(Node)); % establish size of line
Fmax = max(max(abs(Load))); % establish maximum force level
e = [ 1, 0, 0 ; 0, 1, 0 ; 0, 0, 1];
for i = 1 : nLoads
for j = 1 : nNodes
if (Load(i,1) == j)
for k = 1 : 2
F = Load(i, k+1) / Fmax;
xL(1,:) = Node(j,:);
xL(2,:) = Node(j,:) + Llength * F * e(k, 1:nDim);
xL(3,:) = Node(j,:) + Llength * F * e(k, 1:nDim);
if nDim== 2
p = plot(xL(:,1), xL(:,2));
end
if nDim== 3
p = plot3(xL(:,1), xL(:,2),xL(3,:));
end
set(p,'Color','c','LineWidth',8/nDim);
end % for k
end % if Load == j
end % for j, nNodes
end % for i, nLoads
%.. Plot nodes
if nDim==2
plot(Node(:,1), Node(:,2), 'o', 'LineWidth', 2,...
'MarkerFaceColor','w',...
'MarkerEdgeColor','k',...
'MarkerSize',Marker);
view(2);
end
if nDim == 3
plot3(Node(:,1), Node(:,2),Node(:,3), 'o', 'LineWidth', 2,...
'MarkerFaceColor','w',...
'MarkerEdgeColor','k',...
'MarkerSize',Marker);
view(2);
end
% End of Program
I dont know what to do it wont plot in 3D pls help!
Ariana Garciahttps://uk.mathworks.com/matlabcentral/profile/authors/10775461-ariana-garciatag:uk.mathworks.com,2005:Question/4571872019-04-18T14:27:09Z2019-04-20T23:54:34ZHow to wirte algorithm for meshing line element?Hi,
As you see in the figure, there is a truss structure composed of 2 elements and 3 nodes. In my code, ın order to calculate the stifness and mass matrices, X,Y and Z coordinate table(Table1) and elements table(Table 2) which is made manually are needed. The code runs with these initial information. Now, i want to divide these two elements into more elements whose number depends on the user.
My question is about the algoritm that will create Table1 and Table 2 automatically. What do you think about it? Is ıt possbible? If yes, would you write the steps for algorithm. I just need ideas.
hamit Kenanhttps://uk.mathworks.com/matlabcentral/profile/authors/6463402-hamit-kenantag:uk.mathworks.com,2005:Question/4568912019-04-17T09:48:15Z2019-04-20T23:32:53Zreference to non-existent field solidityhi I have error message in matlab 2017
reference to non-existent field 'solidity'
Error in Tumor(line denisty={stats.solidity};
how can I add reference
what did i miss ?Mohamed Nasrhttps://uk.mathworks.com/matlabcentral/profile/authors/15316660-mohamed-nasrtag:uk.mathworks.com,2005:Question/4575732019-04-20T20:05:51Z2019-04-20T23:24:35ZHow can i shift plot?I have a code i need to shift to right my plot by 1,2,3 and 5, respectively on x axis
p=[1/6 1/6 1/6 1/6 1/6 1/6];
q= conv(p,p)
r=conv(q,p)
rr=conv(r,p)
rrr=conv(rr,p)
rrrr=conv(rrr,p)
hold on
subplot(2,2,1),plot(p*100),xlabel('1 dice vs P(x)'),xlim([1,6]),legend('1 dice','P(x)')
hold on
subplot(2,2,2),plot(q*100),xlabel('2 dices vs Q(x)'),xlim([1,13]),legend('2 dices','Q(x)')
hold on
subplot(2,2,3),plot(r*100),xlabel('3 dices vs R(x)'),xlim([1,19]),legend('3 dices','R(x)')
hold on
subplot(2,2,4),plot(rrrr*100),xlabel('6 dices vs S(x)'),xlim([1,37]),legend('6 dices','S(x)')Ege Tunçhttps://uk.mathworks.com/matlabcentral/profile/authors/6193601-ege-tunctag:uk.mathworks.com,2005:Question/4569652019-04-17T15:37:15Z2019-04-20T23:08:24ZSimple moving average code for forecasting stock pricesI need code for predicting stock prices in future using simple moving average calculationMegawaty Lestarihttps://uk.mathworks.com/matlabcentral/profile/authors/14895494-megawaty-lestaritag:uk.mathworks.com,2005:Question/4563022019-04-14T17:57:22Z2019-04-20T22:15:36ZSystem of 2 differential equationsI'm trying to express the following two differential equations in matlab in a form that will allow me to input them into a solver such as ode45. How would I input the following equations into matlab:
dC/dt = (-exp((-10/(T+273)))*C
dT/dt = 1000*(exp((-10)/(T+273))*C-10*(T-20)
where C and T are concentration and temperature (dependent variables) and t is time (independent variable).
Filip Jackowskihttps://uk.mathworks.com/matlabcentral/profile/authors/9548942-filip-jackowskitag:uk.mathworks.com,2005:Question/4575902019-04-20T21:57:59Z2019-04-20T21:57:59ZDifferences in Performance Between Simulink and Matlab FIRsI am building a BPSK recovery system in Simulink, with the end goal of using the HDL coder to implement it on an FPGA.
I designed the algorithm in MATLAB first, and it works fine. However, translating it to Simulink is giving me trouble.
One of my first steps is to filter my data, which I implemented in MATLAB as
filfir2=fir1(100,[0.000001 8e6/Fs*2]); % Fs=30e6
data = filter(filfir2,1,data); %where data is the raw signal
Implementing the same thing in Simulink however, using the Digital Filter Designer (a 100 tap Hamming window direct form FIR with the same cutoff parameters, resulting in the same Bode plot), gives very different results with the same data:
The orange trace is the data filtered through the Simulink block, and the blue trace is the data filtered through Matlab and brought into Simulink with a From Workspace block.
I also tried
1) Importing my Simulink filter into Matlab and using it in Matlab before sending the filtered data to Simulink
2) Importing my Matlab filter (as a dffir block) into Simulink
Both performed identically to the original Matlab filter (i.e the blue trace).
I am wondering if there is a sample time issue or something where the actual simulation is what's causing the issue?
Thanks!
Ethan M.
Ethan Mokhttps://uk.mathworks.com/matlabcentral/profile/authors/6899028-ethan-moktag:uk.mathworks.com,2005:Question/4575722019-04-20T19:58:05Z2019-04-20T21:56:19ZHow to remove weekend from a TimeTable PlotHi!
I want to plot CandleStick pattern based on a TimeTable I have. In this case, I want to remove the gap on my chart caused by weekends. The following code simply remove the weekends from the timetable
T = T(~isweekend(T.DateTime),:);
However, I still have the gap when I plot the Candls since the xaxis shows the weekends gap! How can I remove this gap?
Siahttps://uk.mathworks.com/matlabcentral/profile/authors/3787650-siatag:uk.mathworks.com,2005:Question/4574722019-04-20T01:37:14Z2019-04-20T21:44:37ZHelp me understand the Classifier AppI am looking to create a classifier in Matlab, but I'm having some issues in understanding how exactly it works. I have several data sets of n x 9 arrays with readings from 3 separate 3-axis analog sensors (outputting values in m/s^2), and I want to create a classifier to distinguish between a state described by each of these arrays (walking, standing, running, etc.). I am having significant issue understanding how the classifier app in Matlab can train a model to do such a thing, however, and each time I attempt to "train" it, I get exceptionally poor model performance. I am obviously missing something key here, and I'm not sure where to go. I do have a fairly elementary understanding of classifiers, but I'm finding the documentation available to be confusing. Riley Stromhttps://uk.mathworks.com/matlabcentral/profile/authors/6832935-riley-stromtag:uk.mathworks.com,2005:Question/4575802019-04-20T21:01:51Z2019-04-20T21:43:57Zlimits are too large i have parametrized surface equation T(u,v)=e^(u^2+v^2) i + ln(2*v) j + tan(5*u) k . I used this code to plot it in 3D but it gives error 'limits are too large '. can yu help me pls.
clc; clear all ;
M = 100 ; N = 100 ;
uinf = 100 ;
u = linspace(0,uinf,M) ;
v = linspace(0,2*pi,N) ;
[U V] = meshgrid(u,v) ;
X = exp(U.^2+V.^2) ;
Y = log(2.*V) ;
Z = tan(5*U) ;
surf(X,Y,Z) ;Kuatra Patilhttps://uk.mathworks.com/matlabcentral/profile/authors/15291254-kuatra-patiltag:uk.mathworks.com,2005:Question/4575842019-04-20T21:19:53Z2019-04-20T21:42:57ZHow can I sort an array of structures based upon a particular field in MATLAB?
I've got a eeg_data_all(cell,size = 1*35), which contains 35*3 cells maybe. I want to sort these data by the 'subid'. How can I do this?Wenyi Xiaohttps://uk.mathworks.com/matlabcentral/profile/authors/13762167-wenyi-xiaotag:uk.mathworks.com,2005:Question/4574452019-04-19T21:15:37Z2019-04-20T21:42:54ZWriting equations in a matrix formHi MATLAB experts,
Could any one please help me to write-down the following equations into a matrix form? the initial value of c = zeros(I, L, K, M)
0<= c(i, j, k, m) <= 1 for all k= {1, 2, ...., K} and m = {1, 2, ..., M} and i = {1,...., I} and j = {1,..., L}
0<=sum_{j} sum_{i} c(i,j,k,m) <= 1 for all k= {1, 2, ...., K} and m = {1, 2, ..., M}Su sanhttps://uk.mathworks.com/matlabcentral/profile/authors/14788079-su-santag:uk.mathworks.com,2005:Question/4575872019-04-20T21:34:21Z2019-04-20T21:34:21Zplotting 3D curve and tangent at specified pointi have position vector r(t)=<t , t^2 , 2>, i have to plot it using plot3 function and also plot tangent at the point P(-1 , 1, 2) but i cant figure it out. can you help me please.Kuatra Patilhttps://uk.mathworks.com/matlabcentral/profile/authors/15291254-kuatra-patil