https://kr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — 새 질문2020-11-26T22:01:04Ztag:kr.mathworks.com,2005:Question/6640982020-11-26T22:01:04Z2020-11-26T22:01:04ZRemoving specific cell values from a tableHi so I recently loaded a table from excel into matlab using the xlsread command. Now some of the cells in the table are empty and show in matlab as NaN. I wanted to run the diff command on each of the rows in the table but cannot do that with these NaN cells present. Is there anyway I could possibly remove these specific cells from the table in matlab and then proceed to do the calculation on the cells in each row that actually have a numeric value? Robert A Easterhttps://kr.mathworks.com/matlabcentral/profile/authors/19325453tag:kr.mathworks.com,2005:Question/5037292020-02-05T06:43:34Z2020-11-26T21:59:59ZHow to close the figure contain the uifigure after the alert is closed?I'm not sure if this only happens to me.
Anyways, I create a simple alert using uifigure:
f = uifigure;
mess = "It seems like you have not loaded the model. Please do so before process further.";
title = "Error 101";
uialert(f, mess, title);
After pressing OK, the alert would go away, but the figure that contains the alert is still there (and I have to manually close it).
Is there anyway that it would automatically be closed after the user pressing ok? It's so annoying.
Anh Tranhttps://kr.mathworks.com/matlabcentral/profile/authors/17418102tag:kr.mathworks.com,2005:Question/6640932020-11-26T21:55:10Z2020-11-26T21:55:10ZHow do I keep the number of bins used the same when generating a histogram along with how do I illustrate its depth with color? %Plotting Histogram
for i=1:3000
Zf2=Zf{i,1};
Df2=Df{i,1};
H=[Df2,Zf2];
hist3(H,[10 10])
hold on
end
I am trying to generate a histogram and when set to 1 iteration it generates this histogram
when set to 2 iterations it generates this histogram
How do I keep the number of bins the same and use color to illustrate the depth of the histogram?Andrew Starkhttps://kr.mathworks.com/matlabcentral/profile/authors/16859793tag:kr.mathworks.com,2005:Question/6518482020-11-18T08:25:45Z2020-11-26T21:49:30Zhaw i get two circles from arc noisy?i have a noisy picture and i need to get two circles like this picture bassem ltaiefhttps://kr.mathworks.com/matlabcentral/profile/authors/20376175tag:kr.mathworks.com,2005:Question/6632432020-11-26T08:23:48Z2020-11-26T21:48:58ZHTML Page source infoHello, many-a-times we come across a series of numbered webpages
basePage.html?page=2
basePage.html?page=3
and so forth, wherein there are several fields identified by their labels:
<h2 class="category-heading">Name1</h2>
<label>Parameter1 : </label> <div class="category-related">textOfInterest</div>
<label>Parameter2 : </label> <div class="category-related">textOfInterest</div>
<label>Parameter3 : </label> <div class="category-related">textOfInterest</div>
<h2 class="category-heading">Name2</h2>
<label>Parameter1 : </label> <div class="category-related">textOfInterest</div>
<label>Parameter2 : </label> <div class="category-related">textOfInterest</div>
<label>Parameter3 : </label> <div class="category-related">textOfInterest</div>
<h2 class="category-heading">Name3</h2>
<label>Parameter1 : </label> <div class="category-related">textOfInterest</div>
<label>Parameter2 : </label> <div class="category-related">textOfInterest</div>
<label>Parameter3 : </label> <div class="category-related">textOfInterest</div>
and so on.
How can the "textOfInterest" of one particular parameter, say, Parameter2, of all the Name*, of all the pages,
basePage.html?page=1toInf
be taken (outputted/exported) into one text file, say, Parameter2.txt?
The "textOfInterest" is often alphanumeric with special characters !@#$% also.
Thanks.bhttps://kr.mathworks.com/matlabcentral/profile/authors/5233528tag:kr.mathworks.com,2005:Question/6640882020-11-26T21:33:59Z2020-11-26T21:33:59ZWhy is my code running so slowly in the while loop?Hi, I am using MATLAB R2020a on a MacOS. I am currently trying to calculate the exponentially weighted moving mean by applying a weight to a vector of values using the DSP signal porcessing toolbox algorithm, but it keeps stalling at this point within the while loop without actually giving an error. I am not sure how to solve this without having to preallocate an array outside the loop for storage reasons. Any suggestions would be highly appreciated. Thanks in advance.
while currentcycle > 1
current_expmean_v = (1 - 1/weight(currentcycle))*(previous_expmean_v) + (1/weight(currentcycle))*(values_v);
current_expmean_w = (1 - 1/weight(currentcycle))*(previous_expmean_w) + (1/weight(currentcycle))*(values_w);
endCai Chinhttps://kr.mathworks.com/matlabcentral/profile/authors/18969819tag:kr.mathworks.com,2005:Question/3491882017-07-18T06:06:04Z2020-11-26T21:30:48Zhow to find parallel of resistorsIs there any easy function to calculate parallel and series of resistors when i tried its showing error Wrong number of input arguments for obsolete matrix-based syntax.Kartickeyan Vhttps://kr.mathworks.com/matlabcentral/profile/authors/9025868tag:kr.mathworks.com,2005:Question/6616182020-11-25T07:47:08Z2020-11-26T21:25:14ZHow to rectify a signal and determine the envelope spectra for the FFT? - Envelope analysisHello folks, I am trying to determine the harmful frequencies of my signal. Therefore, I need to do a so called " envelope analysis" for my signal.
I have measured two signal from my sensor. My sensor is located at the tire. Both signals have a shape like sinus. First, I need to rectify the signal. This is done by the following:
XY = sqrt(X.^2+Y.^2);
XY = XY - mean(XY);
Now, I need to determine the envelope curve of my signal. This is done by the following code:
[up1,~] = envelope(XY,30,'analytic');
After that, I need to compute the FFT in order to calculate the harmful frequencies. This is done by the following:
FFTq(up1);
function [f,P] = FFTq(data)
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = length(data); % Length of signal in ms
t = (0:L-1)*T; % Time vector
f = Fs*(0:(L/2))/L; % frequency
FFT = fft(data);
P2 = abs(FFT/L);
P = P2(1:L/2+1);
end
My Matlab program is compiling without any errors. However, the result is not how I expected it. The literature says, that computing the envelope spectra via FFT will provide a better result than computing the FFT. This not the case here. Therefor, I was thinking that my implementation could have some mistakes. Can someone double check my code?
Kind regardsHishan Faizerhttps://kr.mathworks.com/matlabcentral/profile/authors/12903940tag:kr.mathworks.com,2005:Question/6640832020-11-26T21:20:59Z2020-11-26T21:22:35ZMinimize a function with 2 variables and 2 inequality constraints. Hello community,
i have a function with 2 variables to minimize.
f(x,y)= 0.5*(a*x+b*y)+0.5*((x+y)-P)) ^2
0.2 <=x<= 0.6
0<=y<= 0.2
i have to find the values of x, and y
thank you for helping me. Imanitxka imanehttps://kr.mathworks.com/matlabcentral/profile/authors/20464517tag:kr.mathworks.com,2005:Question/6638182020-11-26T15:59:55Z2020-11-26T21:22:19ZHow to access a struct through a field name.I am having difficulty figuring out how to accessa struct by field name. I have only been able to access it by row number. Can someone help me figure this out?
I am creating a struct with the feilds for differnt stocks. How do I write a command to access a field by matching the stock name?
For example:
ProfitCheck = PortfolioCheck(1).marketPrice > PortfolioCheck(1).averageCost;
I can get it to work with row numbers, but instead I want it to look for a stock name?
I have a list of stocks, 'symbols', and want to have the function look through the struct for a matching field name 'PortfolioCheck.symbol = AAPL then return the 'marketPrice' and 'avererageCost'
If you can point me in the right direction that would be wonderful.
Thanks
Allan
% Connects to get the data and creates a struct 'PortfolioCheck'
PortfolioCheck = IBMatlab('action','portfolio');pause(2)
1×4 struct array with fields:
symbol
localSymbol
exchange
secType
currency
right
expiry
strike
position
marketValue
marketPrice
averageCost
realizedPnL
unrealizedPnL
contract
Allan Munrohttps://kr.mathworks.com/matlabcentral/profile/authors/17869019tag:kr.mathworks.com,2005:Question/6639932020-11-26T19:32:10Z2020-11-26T21:17:29ZConvert state-space representation (MIMO) to transfer function matrixhow to convert state-space model (mimo) to transfer function matrixEMAD ALHANIhttps://kr.mathworks.com/matlabcentral/profile/authors/16835221tag:kr.mathworks.com,2005:Question/6640782020-11-26T21:15:46Z2020-11-26T21:15:46ZCurve fitting with custom equation, not using toolboxI have sample X and Y data:
x=[5:5:50];
y=[15 25 32 33 37 35 38 39 41 42];
The data are related by y = a * ( x/(b+x) ) equation
I need to find the coeffs a and b, by curve fitting.
I am trying to use polyfit, but nothing is coming out correctly.
What is the procedure for curve fitting a custom equation? The matalb book I am using is good about basic polynomial equations, and the conversion when converting other equations to polynomials. I am super lost on this one. Thanks.
The answer using Curve fitting toolbox is pasted below, but I can't seem to get there... Help!
General model:
f(x) = (a.*x)/(b+x)
Coefficients (with 95% confidence bounds):
a = 49.58 (45.65, 53.51)
b = 9.943 (7.168, 12.72)
JFhttps://kr.mathworks.com/matlabcentral/profile/authors/17254533tag:kr.mathworks.com,2005:Question/6640732020-11-26T21:14:57Z2020-11-26T21:14:57ZError message saying "Matrix dimensions must agree"Hi
Keep getting error message saying "Matrix dimensions must agree".
not too sure why this is.
any help would be greatly appriciated reuben alexanderhttps://kr.mathworks.com/matlabcentral/profile/authors/17790254tag:kr.mathworks.com,2005:Question/6640682020-11-26T21:12:37Z2020-11-26T21:12:37Zmultiple f-solve functionI am not getting how to solve my error:
My MATLAB code:
Cao=100; % %again we need to make dummy assumption here
% assuming intermediate concentration
Ca1_guess=0.9*Cao;
Ca2_guess=0.5*Cao;
Ca3_guess=0.3*Cao;
k=0.0806;
vt=90;
vtk=vt/k;
Cae=0.05*Cao; % Cae=Cao*(1-0.95)=0.05*Cao
% solving for Ca1,Ca2,Ca3 so V1=V2=V3=V4
Ca1=fsolve(@myfun1,[Ca1_guess]);
Ca2=fsolve(@myfun2,[Ca2_guess]);
Ca3=fsolve(@myfun3,[Ca3_guess]);
V1=vtk*((Cao-Ca1)/Ca1);
V2=vtk*((Ca1-Ca2)/Ca2);
V3=vtk*((Ca2-Ca3)/Ca3);
V4=vtk*((Ca3-Cae)/Cae);
V=V1+V2+V3+V4
function main
myfun1(Ca1)
myfun2(Ca2)
myfun3(Ca3)
Cao=100;
k=0.0806;
vt=90;
vtk=vt/k;
Cae=0.05*Cao;
V1=vtk*((Cao-Ca1)/Ca1);
V2=vtk*((Ca1-Ca2)/Ca2);
V3=vtk*((Ca2-Ca3)/Ca3);
V4=vtk*((Ca3-Cae)/Cae);
function myfun1(Ca1)
Cao=100;
Cae=0.05*Cao; % Cae=Cao*(1-0.95)=0.05*Cao
k=0.0806;
vt=90;
vtk=vt/k;
V1=vtk*((Cao-Ca1)/Ca1);
V2=vtk*((Ca1-Ca2)/Ca2);
V3=vtk*((Ca2-Ca3)/Ca3);
V4=vtk*((Ca3-Cae)/Cae);
function myfun2(Ca2)
Cao=100;
Cae=0.05*Cao; % Cae=Cao*(1-0.95)=0.05*Cao
k=0.0806;
vt=90;
vtk=vt/k;
V1=vtk*((Cao-Ca1)/Ca1);
V2=vtk*((Ca1-Ca2)/Ca2);
V3=vtk*((Ca2-Ca3)/Ca3);
V4=vtk*((Ca3-Cae)/Cae);
function myfun3(Ca3)
Cao=100;
Cae=0.05*Cao; % Cae=Cao*(1-0.95)=0.05*Cao
k=0.0806;
vt=90;
vtk=vt/k;
V1=vtk*((Cao-Ca1)/Ca1);
V2=vtk*((Ca1-Ca2)/Ca2);
V3=vtk*((Ca2-Ca3)/Ca3);
V4=vtk*((Ca3-Cae)/Cae);
end
end
end
F=V4-V3-V2-V1;
end
% we are aiming for difference in the volume to be zero
The command window message is:
>> mez
Undefined function or variable 'myfun1'.
Error in fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
Error in mez (line 12)
Ca1=fsolve(@myfun1,[Ca1_guess]);
Amnia Al-Hammadihttps://kr.mathworks.com/matlabcentral/profile/authors/17994481tag:kr.mathworks.com,2005:Question/6635882020-11-26T12:24:25Z2020-11-26T21:03:18ZMATLAB cannot integrate trigonometry in the form of degreeAn interesting problem in MATLAB.
Normally, when doing hand-calculation for trigonometry, we can either calculate the equations in degree or in radian. However, the integral of trigonometry in MATLAB (other math-softwares as well) is a different story.
Lets start with a simple example, the integral of "cos(x)" from -pi/2 to pi/2.
If calculate by hand, you will find the answer is "sin(pi/2) - sin(-pi/2)", which equals to 2. Also, if using degree, it becomes "sind(90) - sind(-90) = 2". (I use "sind" to distinguish them, but in real-world when we calculate by hand, we still use "sin" when it is degree)
In MATLAB, you can write codes to calculate this using functions such as "integral", "int" and "vpaintegral". I use "int" here, as shown below.
syms x
f = cos(x);
int(f,-pi/2,pi/2)
Then, MATLAB will gives you the correct answer, which is 2.
ans = 2
However, if you use degree for this calculation, the codes should be written as below.
syms x
f = cosd(x); % x is in degree
int(f,-90,90) % from -90 degrees to 90 degrees
The answer given is 360/pi, which is 114.65. A big difference. This answer is incorrect compare with what we expected.
ans = 360/pi
What happened?
After discovery, I found that this issue is caused by MATLAB's internal algorithm when dealing with trigonometry in degree (cosd, sind, tand etc.)
MATLAB turns "cosd(x)" into "cos(x*pi/180)" when you use the degree form of trigonometry.
After integral cos(x*pi/180) becomes (pi/180)*sin(x*pi/180). Therefore, the calculation over [-90 90] becomes
(180/pi)* ((sin(90*pi/180))-(sin(-90*pi/180)))
If you just look at the second polynomial, it gives you 2, which is the answer it should be, but there is a (180/pi) at the front, which leads to an incorrect answer. At this time, the result is 180*2/pi.
Overall, the conclusion is that, NEVER calculate integral of trigonometry with degree, but RADIAN instead. For other complicated non-integral calculations, it is also better to use RADIAN as the form of trigonometry.
In addition, I think MATLAB can solve this problem so that we can use degree to do this calculation without error.Jianming Wanghttps://kr.mathworks.com/matlabcentral/profile/authors/19346608tag:kr.mathworks.com,2005:Question/6624282020-11-25T19:55:15Z2020-11-26T20:59:53ZExample 'Build a Map from Lidar Data Using SLAM' ConfusionHi,
I'm trying to follow the example 'Build a Map from Lidar Data Using SLAM' from the computer vision toolbox.
https://www.mathworks.com/help/vision/ug/build-a-map-from-lidar-data-using-slam.html
In the function helperComputeInitialEstimateFromINS, there are three lines that I really tried to understand but without sucess.
My problem is not in the theory but in this particular implementation. Here are the lines
% The INS readings are provided with X pointing to the front, Y to the left
% and Z up. Translation below accounts for transformation into the lidar
% frame.
insToLidarOffset = [0 -0.79 -1.73]; % See DATAFORMAT.txt
Tnow = [-insData.Y(end), insData.X(end), insData.Z(end)].' + insToLidarOffset';
Tbef = [-insData.Y(1) , insData.X(1) , insData.Z(1)].' + insToLidarOffset';
The DATAFORMAT.txt file says that the transform from IMU to lidar is [0.79 0 1.73]. Why is it not implemented this way then?
Why are X and Y coordinates inverted and negative in Tnow and Tbef? It is clear in the DATAFORMAT.txt that the X coordinates is front, Y coordinates is left and Z coordinates is up
What makes even less sense to me is that the transformation to insToLidarOffset (i.e.: switching X,Y then put them negative) and the transformation to Tnow and Tbef (i.e.: switching X,Y then just put Y negative) is not even the same.
I appreciate the time you take to answer this question,
MarcMarc Tisonhttps://kr.mathworks.com/matlabcentral/profile/authors/20172091tag:kr.mathworks.com,2005:Question/6640632020-11-26T20:58:48Z2020-11-26T20:58:48ZMATLAB NEURAL NETWORKS TOOLBOXThe basic single-layer feed-forward (SLFF) program uses a threshold activation function and the Delta learning rule. Try to learn (a) the AND patterns, (b) the OR patterns, (c) the XOR patterns.Anwer Alkaabihttps://kr.mathworks.com/matlabcentral/profile/authors/17591928tag:kr.mathworks.com,2005:Question/6639132020-11-26T17:16:08Z2020-11-26T20:57:07Z Use dynamic field namesDear all,
writing a dynamic field names calling like:
newModif = app.UITableModif.Data ;
oldModif = app.UITablePModif.Data ;
num = 1 ;
for i = 1:7
str=['M',num2str(i),CheckBox.Value]
if app.(str) == 1 %newModif
modifiers(num) = newModif(i,1);
num=num+1;
end
str=['MP',num2str(i),CheckBox.Value]
if app.(str) == 1 %oldModif
modifiers(num) = oldModif(i,1);
num=num+1;
end
end
I'm obtaining an error calling the name field as app.(str)
What I did wrong?
Thanks,
FrancescoFrancesco Petrosinohttps://kr.mathworks.com/matlabcentral/profile/authors/18499764tag:kr.mathworks.com,2005:Question/6639332020-11-26T17:50:36Z2020-11-26T20:56:12ZCreating M histograms from an NxM table on separate plots Hi there,
I have an N x M table and I am trying to create M histograms on different plots, I can't seem to figure out how to plot them on different figures. If I hold on, they all plot on the same axis'
data = readtable('file.csv'); % Import in wine raw data
predictors = data(:,1:width(data)-1); % remove quality as it is our output
headers = predictors.Properties.VariableNames; % Get predictor labels
%% Lets check to see how our predictors are distributed
statarray = grpstats(predictors,[],{'mean','std'})
for k = width(headers);
a = table2array(predictors(:,k)); % Converting from table to array for hist
histogram(a)
title(headers(1,k))
end
I'm also not sure why I can't pass a table row to a histogram and need to table2array the data.
Any help would be greatly appreciated. Thank youJeremy Brecevichttps://kr.mathworks.com/matlabcentral/profile/authors/20142413tag:kr.mathworks.com,2005:Question/406642012-06-08T16:15:02Z2020-11-26T20:54:14Zfuzzy logic with regressionDear
I would like to know whether the fuzzy logic tool box can do the regression. I am working on equations that have some parameter which are fuzzy. If I want to fit these equations which have some fuzzy parameters with data, can I use the fuzzy tool box? I saw that the ANFIS did the least square. However, it seems to work on least square of error and it seems to me that it would make the membership function fit the data. It didn't take the equation as it part of calculation. Do I understand it correctly? Paulhttps://kr.mathworks.com/matlabcentral/profile/authors/1942533tag:kr.mathworks.com,2005:Question/6625332020-11-25T22:08:49Z2020-11-26T20:49:21ZError Using Accumarray "Requested array exceeds the maximum possible variable size"I am trying to generate a histogram but I keep on getting this error
Error using accumarray
Requested array exceeds the maximum possible variable size.
Error in Analyze (line 170)
zm=accumarray([Dfr' Zfr'],1,[nn nn]);
My code is here
n=100;
for i=1:1
ZZ=Zf{i};
DD=Df{i};
nn=repelem(n,144);
Zf2=linspace(min(ZZ(:)),max(ZZ(:)),n);
Df2=linspace(min(DD(:)),max(DD(:)),n);
Zfr=interp1(Zf2,1:numel(Zf2),ZZ,'nearest');
Dfr=interp1(Df2,1:numel(Df2),DD,'nearest');
zm=accumarray([Dfr' Zfr'],1,[nn nn]);
figure, surf(zm);
hold on
end
A segment of Df and Zf are pictured above
Andrew Starkhttps://kr.mathworks.com/matlabcentral/profile/authors/16859793tag:kr.mathworks.com,2005:Question/6623982020-11-25T19:17:50Z2020-11-26T20:47:43Zmatlab.graphics.internal.figfile.FigFile/readHello everyone, I got this error and I do not know how to solve. Could you help me finding the problem in the following code please?
function varargout = Bai1(varargin)
% BAI1 MATLAB code for Bai1.fig
% BAI1, by itself, creates a new BAI1 or raises the existing
% singleton*.
%
% H = BAI1 returns the handle to a new BAI1 or the handle to
% the existing singleton*.
%
% BAI1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BAI1.M with the given input arguments.
%
% BAI1('Property','Value',...) creates a new BAI1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Bai1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Bai1_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Bai1
% Last Modified by GUIDE v2.5 27-Nov-2020 02:23:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Bai1_OpeningFcn, ...
'gui_OutputFcn', @Bai1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Bai1 is made visible.
function Bai1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Bai1 (see VARARGIN)
% Choose default command line output for Bai1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Bai1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Bai1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Ch??ng trình ví du 3.1 v? v? ?? th? c?a h? th?ng ?i?u khi?n t? ??ng
disp('MO PHONG HE THONG DIEU KHIEN TU DONG - THM')
clc;
% Khai bao bien
syms a b c d max k1 k2 t1 t2 tm tod xichma gd gm k km ky i
y = ones(1,1000);
k1 = get(handles.edit1,'String');
k1 = str2num(k1);
k2 = get(handles.edit2,'String');
k2 = str2num(k2); %Chuy?n ??i t? chu?i ký t? sang d?ng s?
t1 = get(handles.edit3,'String');% Nh?n chu?i ký t? ? edit3 gán cho t1
t1 = str2num(t1); %Chuy?n ??i t? chu?i ký t? sang d?ng s?
t2 = get(handles.edit4,'String');% Nh?n chu?i ký t? ? edit4 gán cho t2
t2 = str2num(t2); %Chuy?n ??i t? chu?i ký t? sang d?ng s?
t = get(handles.edit5,'String');% Nh?n chu?i ký t? ? edit1 gán cho t
t = str2num(t); %Chuy?n ??i t? chu?i ký t? sang d?ng s?
y(1,1)=0; % Khai bao phan tu y(1) = 0
y(1,2)=0; % Khai bao phan tu y(2) = 0
y(1,3)=0; % Khai bao phan tu y(3) = 0
a=8*t1*t2+4*t1*t+4*t2*t+2*t*t+k1*k2*t*t*t;
b=-24*t1*t2-4*t1*t-4*t2*t+2*t*t+3*k1*k2*t*t*t;
c=24*t1*t2-4*t1*t-4*t2*t-2*t*t+3*k1*k2*t*t*t;
d=-8*t1*t2+4*t1*t+4*t2*t-2*t*t+k1*k2*t*t*t;
for k =1:997
y(1,k+3)=(-b*y(1,k+2)-c*y(1,k+1)-d*y(1,k)+8*k1*t*t*t)/a;
end
% Ch??ng trình ví du 3.1 v? v? ?? th? c?a h? th?ng ?i?u khi?n t? ??ng
% Tim gia tri lon nhat
max = y(1,1);
for k =1:997
if y(1,k)>max
max = y(1,k);
km = k;
end
end
set(handles.edit6,'String',max);
set(handles.edit10,'String',t*km);
%================================
%Tim khoang thoi gian on dinh
k =1000;
while abs((y(1,k)-(1/k2))/(1/k2))<=0.05
k = k-1;
tod=k*t;
end
set(handles.edit7,'String',tod);
% Ch??ng trình ví du 3.1 v? v? ?? th? c?a h? th?ng ?i?u khi?n t? ??ng
%=================================
%Tim do qua dieu chinh
xichma = (max-1/k2)*100/(1/k2);
set(handles.edit8,'String',xichma);
%=================================
%Ve do thi
tx = 1:1000;
tx = t*tx;
subplot(2,2,2);
plot(tx,y)
title('DAC TINH QUA DO CUA HE DKTD');
xlabel('t(Second)')
ylabel('y(t)')
hold on
grid on
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hoi=questdlg('Ban muon thoat khoi chuong trinh?',...
'THUC SU MUON THOAT?','Yes','No','No');
if strcmp(hoi,'Yes')
close
if strcmp(hoi,'No')
return;
end
end
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit7 as text
% str2double(get(hObject,'String')) returns contents of edit7 as a double
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit10_Callback(hObject, eventdata, handles)
% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit10 as text
% str2double(get(hObject,'String')) returns contents of edit10 as a double
% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_2 (see GCBO)
Hoàng Duyhttps://kr.mathworks.com/matlabcentral/profile/authors/20453813tag:kr.mathworks.com,2005:Question/6098212020-10-10T07:40:16Z2020-11-26T20:46:02ZSVR regression in regression learner APP When traning in Regression Learner App in matlab, the R2 and RMSE values are differing eventhough the same data set is been used. Is regression learnear app reliable for SVR traning ? sa phttps://kr.mathworks.com/matlabcentral/profile/authors/16625795tag:kr.mathworks.com,2005:Question/6640582020-11-26T20:45:09Z2020-11-26T20:45:09ZVarying results for the same modelWe are modelling a combined cycle pwer plant. When we ran GT seperatly we got the desired result for exhaust temperature, but when we connected the GT to HRSG and ST we got a different result.. My question is, how can GT results change if it is at the beginning of the model and nothing goes back to it ?
Fatima Hassanhttps://kr.mathworks.com/matlabcentral/profile/authors/13158060tag:kr.mathworks.com,2005:Question/1214432014-03-13T20:50:16Z2020-11-26T20:44:14ZError installing third party package Arduino software: Invalid zip fileI have the 2013a version of matlab and been trying to install the simulink support package for arduino hardware, but I keep getting the following error:
"Error installing third party package Arduino software: Invalid zip file "C:\MATLAB\SupportPackages\R2013a\downloads\arduino-1.0-windows.zip"."
and then the installation stops.
N.B.: I using windows 8.Haninhttps://kr.mathworks.com/matlabcentral/profile/authors/5142446tag:kr.mathworks.com,2005:Question/6536882020-11-19T16:11:16Z2020-11-26T20:37:53ZCell array Numeric data splittingMy requirement is to create generate numerous complex matrices of 15x15, and extract the diagonal elements and upper triangle elements as column vectors, and finally combine them into a single column vector.
As a part of the implementation I have done some code which looks similar to this.
I have created a program to generate 6 complex matrices using for loop, and stores them in a cell array.
Code 1:
clear all;
close all;
clc;
N=15;
k=6;
C=cell(k,1)
for j = 1:k
C{j}= rand(N,N) + 1i*rand(N,N); % Complex Matrix
end
Now the cell C 6 x1 contains 15x15 complex double numeric data in each cell array.
For extracting the diagonal elements extract the diagonal elements and upper triangle elements as column vectors and finally combine them into a single column vector for a Matrix C I have the following code.
Code 2:
D = diag(C)
L = triu(C,1)
U = tril(C,-1)
V= [D; real(U(:)); real(L(:))].
I would like to combine this Code 2 approach for the Cell C obtained in Code1 by splitting each array in cell C- 6x1 with 15x15 in each cell into differnt arrays/ matrices of 15x15 order and then do the code2 operation.
Is it better to use the cell array approach to create a loop of matrices, or is there any other way to do? Please guide me.Karthik Nagarajhttps://kr.mathworks.com/matlabcentral/profile/authors/11245659tag:kr.mathworks.com,2005:Question/6639882020-11-26T19:31:56Z2020-11-26T20:37:25ZHow to Solve an Equation with Integral and Gamma functions?Hello
Dear all,
I need to solve an equation, L, that includes a second function, F, that also includes the lower incomplete gamma function, gammainc. Unfortunately, I cannot correctly program it in MATLAB.I appreciate your help. Please see the pictures attached to see the functions (L and F).
P.S. I initially attempted to solve it through numerical integration (trapz), but my results are not correct! The correct results should look like the second attached picture.
Note that the parameter s is an array (e.g. s = 0.015), or a vector (s = 0.015:0.001:0.1)
I really appreciate your response in advance.
Benjaminhttps://kr.mathworks.com/matlabcentral/profile/authors/11767993tag:kr.mathworks.com,2005:Question/6618532020-11-25T10:45:30Z2020-11-26T20:33:25Zfft finding oscillation frequency and strouhal number for liftHello all,
I have a data which comes from an oscillating plate in a laminar flow. (please see the attachment). my sampling frequency is 2000 Hz. I am trying find out frequency magnitude and strouhal number graphs with fft. For the frequency plot, I would like to neglect all frequencies above the Nyquist frequency. I have looked at the examples on the page, followed them and created my scripts as below but at some points I became confused and not sure about my script is right or not. So, I am wondering does any of you help me to solve this problem ?
Thanks,
Megi
Megi Clenhttps://kr.mathworks.com/matlabcentral/profile/authors/20448906tag:kr.mathworks.com,2005:Question/6603332020-11-24T12:20:51Z2020-11-26T20:32:15ZBring some signals to the same start value and end valueHello,
I need some help. I want to bring some Signals to the same start end value. How I can do this quickly and easy?
Here is our code to plot the signals in one plot:
clear all
close all
F = 2000;
load('Spiro_4.mat');
data4 = data;
Atemfluss4 = data(1:end,1);
Volumen4 = data(1:end,2);
F = 2000; % sampling frequency
T4= 1/F; %Periodendauer
t4= ([0:T4:25.889]); % time vector
load('Spiro_3.mat');
data3 = data;
Atemfluss3 = data(1:end,1);
Volumen3 = data(1:end,2);
F = 2000; % sampling frequency
T3= 1/F; %Periodendauer
t3= ([0:T3:28.444999]); % time vector
load('Spiro_2.mat');
data2 = data;
Atemfluss2 = data(1:end,1);
Volumen2 = data(1:end,2);
F = 2000; % sampling frequency
T2= 1/F; %Periodendauer
t2= ([0:T2:25.979999]); % time vector
load('Spiro_1.mat');
data1 = data;
Atemfluss1 = data(1:end,1);
Volumen1 = data(1:end,2);
F = 2000; % sampling frequency
T1= 1/F; %Periodendauer
t1= ([0:T1:33.414]); % time vector
figure;
plot(t1,Volumen1,t2,Volumen2,t3,Volumen3,t4,Volumen4);
ylabel('Volume in litres');
xlabel('Zeit in s');
Thank you for support.
[EDITED, Jan, Code formatted]Daniel Sedlaczekhttps://kr.mathworks.com/matlabcentral/profile/authors/16517873tag:kr.mathworks.com,2005:Question/6640532020-11-26T20:30:30Z2020-11-26T20:31:12Zrounding and displaying datetime in plot x-axisI want to display the energy versus the time of up to 15 measurements. Currently I can either get a satisfying number and position of ticks but with an annoying date stamp (option 1) or can remove the date stamp but get a weird rounding error. I would like to get rid of the date stamp while keeping the options to have "round" values of my datetime.
Figure 1 is option 1 and figure 2 is option 2.
You find a sample code further beneath (I adjusted it so you can run it yourself, in my case the data is extracted from a text file and the datetime is not always the same vector, but all measurements are done within a day and to not go over midnight), to switch from option 1 to 2 simply uncomment BOTH lines with
%ax = gca;
%ax.XTickLabel = datestr(linspace(xtick_start,xtick_end,NumTicks),'HH:mm');
I hope the solution is straightforwar and I was just too stupid to realize my mistake... Many thanks in advance either way
n_experiments = 5;
n_length = 10;
%generate random data (not done in my application)
for i_n_experiments = 1:n_experiments
t1 = datetime(2013,11,1,8,0,0);
t2 = datetime(2013,11,1,15,30,0);
test_data(i_n_experiments).datetime = linspace(t1,t2,n_length);
test_data(i_n_experiments).E = rand(n_length,1);
end
%define some quantities related to the size of the structure array
[~,n_series] = size(test_data);
n_series_vec = 1:n_series;
ax_vec = zeros(1,n_series);
t = tiledlayout('flow');
for i = 1:n_series
ax_vec(i) = nexttile;
plot(test_data(i).datetime, test_data(i).E, 'Linewidth', 4)
% THIS IS THE PART I AM CONCERNED WITH
NumTicks = 5; %define number of ticks displayed
xtick_start = dateshift(test_data(i).datetime(1), 'end', 'hour'); %round the datetime, so labels of adjacent graphs won't overlap
xtick_end = dateshift(test_data(i).datetime(end), 'start', 'hour');
%ax = gca;
%ax.XTickLabel = datestr(linspace(xtick_start,xtick_end,NumTicks),'HH:mm');
set(gca,'XTick',linspace(xtick_start,xtick_end,NumTicks))
end
%synchronize y axis
linkaxes([ax_vec(1:n_series)],'y') Joel Affolterhttps://kr.mathworks.com/matlabcentral/profile/authors/19886538tag:kr.mathworks.com,2005:Question/2678602016-02-12T16:24:37Z2020-11-26T20:26:30ZHow to minimize the size of MATLAB Runtime Libraries (MCR)Hi,
Is there a way to set installation options for MATLAB Runtime libraries (MCR)?
The objective is to choose only the relevant libraries to my application in order to minimize the size of the libraries on the system.
Note that I've searched online a lot but found no up-to-date answer.
Thanks!Pansyhttps://kr.mathworks.com/matlabcentral/profile/authors/3079871tag:kr.mathworks.com,2005:Question/968062010-12-27T18:11:00Z2020-11-26T20:21:54ZHow do I create a line made of markers in my Scope within Simulink?How do I create a line made of markers in my Scope within Simulink?
Instead of getting a thick line, I would like a line made of markers in my Scope.
MathWorks Support Teamhttps://kr.mathworks.com/matlabcentral/profile/authors/4622813tag:kr.mathworks.com,2005:Question/6576482020-11-22T16:41:57Z2020-11-26T20:19:45ZScript: Indexing in function problem Hi,
I want to creat a function like this:
c(t+1,i)= c(t,i)-1/(dx^2)*(-D*(c(t,i+1)-c(t,i))-(-D*(c(t,i)-c(t,i-1)))) to solve this by ode4
and I do it like this:
but it dosen't work. I don't now why. Could someone explain to my why it dosen't work and how to indexing in fuction, pleace?
Norbert Raduckihttps://kr.mathworks.com/matlabcentral/profile/authors/18455440tag:kr.mathworks.com,2005:Question/6639682020-11-26T19:18:45Z2020-11-26T20:18:43Zi am geting error in this line why Error: File: dfdddd.m Line: 32 Column: 89 Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters. % M-file: torque_speed_curve.m
% M-file create a plot of the torque-speed curve of the
% induction motor of Example 7-5.
% First, initialize the values needed in this program.
r1 = 0.641; % Stator resistance
x1 = 1.106; % Stator reactance
r2 = 0.332; % Rotor resistance
x2 = 0.464; % Rotor reactance
xm = 26.3; % Magnetization branch reactance
v_phase = 460 / sqrt(3); % Phase voltage
n_sync = 1800; % Synchronous speed (r/min)
w_sync = 188.5; % Synchronous speed (rad/s)
% Calculate the Thevenin voltage and impedance from Equations
% 7-41a and 7-43.
v_th = v_phase * ( xm / sqrt(r1^2 + (x1 + xm)^2) );
z_th = ((j*xm) * (r1 + j*x1)) / (r1 + j*(x1 + xm));
r_th = real(z_th);
x_th = imag(z_th);
% Now calculate the torque-speed characteristic for many
% slips between 0 and 1. Note that the first slip value
% is set to 0.001 instead of exactly 0 to avoid divide-
% by-zero problems.
s = (0:1:50) / 50; % Slip
s(1) = 0.001;
nm = (1 - s) * n_sync; % Mechanical speed
% Calculate torque for original rotor resistance
for ii = 1:51
t_ind1(ii) =(3 * v_th^2 * r2)./((w_sync.*s(ii).*((r_th+(r2./s(ii)).^2 + (x_th+x2)^2));
end
% Calculate torque for doubled rotor resistance
% Plot the torque-speed curve
plot(nm,t_ind1,'Color','k','LineWidth',2.0);
hold on;
xlabel('\itn_{m}','Fontweight','Bold');
ylabel('\tau_{ind}','Fontweight','Bold');
title ('Induction Motor Torque-Speed Characteristic','Fontweight','Bold');
legend ('Original R_{2}','Doubled R_{2}');
grid on;
hold off;
Bader Herzallahhttps://kr.mathworks.com/matlabcentral/profile/authors/17716299tag:kr.mathworks.com,2005:Question/6640482020-11-26T20:18:19Z2020-11-26T20:18:19Zhow to estimate parameters of nonlinear complex equations having summation termshow to use MLE for mathematical model having cdf/mean value function
m(t) = x(1-exp(yt)) +at^b +zt and intensity function as
I(t)= xyexp(-yt) + abt^(b-1) +z
for estimating parameters x,y,z,a and b what i need to do...do i need to write a script or do i need to solve the attached equations using fsolve and how..can you suggest any tutorial or course which help me in analysing the above model.
thanks
shalinishalini sharmahttps://kr.mathworks.com/matlabcentral/profile/authors/20456342tag:kr.mathworks.com,2005:Question/6639232020-11-26T17:27:51Z2020-11-26T20:18:16ZCreate 200 Variables using columns of data for use in Random ForestHappy Thanksgiving!
I was wondering if anyone could help me create 200 variables based off of a Sheet of 285 columns and 1000 rows that could be used in random forest. Instead of typing the variables out one by one is there a way to automatically assign variables that could be used and plugged into the numLevels function attached?Jon Dewlandhttps://kr.mathworks.com/matlabcentral/profile/authors/11942519tag:kr.mathworks.com,2005:Question/6640082020-11-26T19:50:12Z2020-11-26T20:16:14Z4th degree question plotingCtg =[0.322;0.122;0.084;0.053;0.031;0.01];
t =[0 20 40 60 80 100];
% 4th degree Equation
R = 1.914e-08*t4 -4.753e-06*t3 + 0.0004167*t2 – 0.01639*t+ 0.3213
How can I plot it to be like the attached image? please anyony
AHMED AKBAShttps://kr.mathworks.com/matlabcentral/profile/authors/20023132tag:kr.mathworks.com,2005:Question/1442732014-07-31T20:36:02Z2020-11-26T20:15:59ZNew Script keeps opening in new window instead of a tabSo, stupid question. I accidentally did something on my script file and now when I hit new script, it opens a new script in a new window instead of a new tab. Can someone tell me what I did and how to reverse it.
ThanksHailhttps://kr.mathworks.com/matlabcentral/profile/authors/3032729tag:kr.mathworks.com,2005:Question/6640432020-11-26T20:14:49Z2020-11-26T20:14:49ZWhen simulating the response to a specific input signal, the input data U must be a matrix with as many rows as samples in the time vector T, and as many columns as input channels.Hi all, I'm getting an error with the u matrix, the situation is 3 train carts coming to a rest so, there is a pulling force represented by the u matrix. I left in the sinusoidal force as that gave results but, I would like to get results with initial parameters.
Thanks, Zain
clear
clc
m1 = 69000;
m2 = 65000;
m3 = 126000;
k1 = 8000;
k2 = 8500;
c1 = 5200;
c2 = 6000;
%to = 0:0.5:10
Z = zeros(3);
M = [m1 0 0; 0 m2 0; 0 0 m3];
Co = [c1 -c1 0;-c1 (c2+c1) -c2; 0 -c2 c2];
K = [k1 -k1 0; -k1 (k1+k2) -k2; 0 -k2 k2];
Minv = inv(M);
I = eye(3);
MC = Minv*Co;
KC = Minv*K;
A = [-MC -KC; I Z];
B = eye(6);
C = eye(6);
D = zeros(6);
state = ss(A,B,C,D)
t = 0:0.01:20;
%u = 158005*sin(3.142*t);
u = [87567; 0; 0; 0; 0; 0];
u = repmat(u, 6, 1);
sys = ss(A,B,C,D);
x0 = [4.17;4.17;4.17;0;0;0];
y = lsim(state,u,t,x0);
hold on
x1 = y(:,1);
figure(1)
xlabel('Time (s)');
ylabel('Displacement');
title('Displacement against time')
plot(t,x1)
grid
hold offZain Ziahttps://kr.mathworks.com/matlabcentral/profile/authors/19963115tag:kr.mathworks.com,2005:Question/6635932020-11-26T12:29:24Z2020-11-26T20:07:54ZHow to read every i data in the UIAXES plotted data ?Hi All
I have got a plot in my aap designer window, and after plotting some 2D data on it, I want to read and save only some specific data from this plot and not whole of it how do I do that
app.UIAxes.Children(i).YData = somefunction(b, a, app.UIAxes.Children(i).YData);
or somehow I should have access to numerical values in YData
I am trying the following but not succeeding, I have more than one plot
for i=1:numel(app.UIAxes.Children)
app.fitY = [app.fitY; app.UIAxes.Children(i).YData];
app.fitt = [app.fitt; app.UIAxes.Children(i).XData];
assignin('base','appdatay',app.UIAxes.Children(i).XData)
assignin('base','appdatax',app.UIAxes.Children(i).YData)
app.UIAxes.Children(i).YData = app.UIAxes.Children(i).YData(1:redrate:numel(app.fitY));
endfarzadhttps://kr.mathworks.com/matlabcentral/profile/authors/2231846tag:kr.mathworks.com,2005:Question/6640382020-11-26T20:07:35Z2020-11-26T20:07:35ZReshape a matrix using another matrix with specific limitsHello,
I have lat/long data which is interpolated with another softwater but I want to do the same here in Matlab.
Matrix A has such dimension [21,23]
Matrix B which is interpolated has has such dimention [10384,10861]
How matrix B from [21,23] is converted to [10384,10861] is because that used this values;
0.500000000000000 'offset_x'
0.500000000000000 'offset_y'
5.192000000000000e+02 'subsampling_x'
4.936818181818182e+02 'subsampling_y'
So how can I convert Matrix A to have the same dimension as B [10384,10861]?
I have used imresize(A,[10384 10861]); but since I did not consider the exact intervals the expected values are not correct.
I appreciate any help on this subject.
Thank you in advance.
FShhttps://kr.mathworks.com/matlabcentral/profile/authors/15430989tag:kr.mathworks.com,2005:Question/6640332020-11-26T20:06:32Z2020-11-26T20:06:32ZPlot please help / plot the domain of transfer function How can I plot the transfer function of this function
B(s)=5s^3+30s^2+55s+30/A(s)=s^3+9s^2+33s+65
Melika Efthttps://kr.mathworks.com/matlabcentral/profile/authors/20177607tag:kr.mathworks.com,2005:Question/4363992018-12-18T21:22:54Z2020-11-26T20:05:22ZHow can I raise a power in gui edit textHello everyone
As i asked on the title I want to raise a power in edit text. like P1
I tried with latex but it didn't work for me
Thank youEmre Kaynarhttps://kr.mathworks.com/matlabcentral/profile/authors/11632011tag:kr.mathworks.com,2005:Question/6639482020-11-26T18:07:20Z2020-11-26T20:02:49Zhow to use "fullfile" with exportgrahicsOne can use fullfile for saveas
saveas(gcf, fullfile(directory, fileName),'jpeg')
But when I try to use
exportgraphics(gcf, fullfile(directory, fileName)', 'eps', 'Resolution',3000)
Then I get an error message
Input must be a row vector of characters or string scalar
What is the next step?alpedhuezhttps://kr.mathworks.com/matlabcentral/profile/authors/10930090tag:kr.mathworks.com,2005:Question/6639732020-11-26T19:20:29Z2020-11-26T19:59:24Zhave f-solve functionI find error in my code shown below:
Ca0=100; %again we need to make dummy assumption here
Ca1_guess=0.9*Ca0;
Ca2_guess=0.8*Ca0;
Ca3_guess=0.7*Ca0;
k=0.0806;
vt=90;
h=vt/k;
Ca4=0.05*Ca0; % Ca4=Ca0*(1-0.95)=0.05*Ca0
% the reactor volume is the same so using fsolve to solve for Ca1,Ca2,and
% Ca3
Ca1= fsolve(@myfun1,[Ca1_guess]);
Ca2= fsolve (@myfun2,[Ca2_guess]);
Ca2= fsolve (@myfun3,[Ca3_guess]);
V1=h*((Ca0-Ca1)/Ca1);
V2=h*((Ca1-Ca2)/Ca2);
V3=h*((Ca2-Ca3)/Ca3);
V4=h*((Ca3-Ca4)/Ca4);
V=V1+V2+V3+V4
function main
myfun1 (Ca1)
myfun1 (Ca2)
myfun1 (Ca3)
Ca0=100;
Ca4=0.05*Ca0;
vt=90;
h=vt/k;
V1=h*((Ca0-Ca1)/Ca1);
V2=h*((Ca1-Ca2)/Ca2);
V3=h*((Ca2-Ca3)/Ca3);
V4=h*((Ca3-Ca4)/Ca4);
function myfun1(Ca1)
Ca0=100;
Ca4=0.05*Ca0;
vt=90;
h=vt/k;
V1=h*((Ca0-Ca1)/Ca1);
V2=h*((Ca1-Ca2)/Ca2);
V3=h*((Ca2-Ca3)/Ca3);
V4=h*((Ca3-Ca4)/Ca4);
function myfun2(Ca2)
Ca0=100;
Ca4=0.05*Ca0;
vt=90;
h=vt/k;
V1=h*((Ca0-Ca1)/Ca1);
V2=h*((Ca1-Ca2)/Ca2);
V3=h*((Ca2-Ca3)/Ca3);
V4=h*((Ca3-Ca4)/Ca4);
function myfun3(Ca1)
Ca0=100;
Ca4=0.05*Ca0;
vt=90;
h=vt/k;
V1=h*((Ca0-Ca1)/Ca1);
V2=h*((Ca1-Ca2)/Ca2);
V3=h*((Ca2-Ca3)/Ca3);
V4=h*((Ca3-Ca4)/Ca4);
end
end
end
F=V4-V3-V2-V1; %F=0, because V1=V2=V3=V4
end
the comand window:
Undefined function or variable 'myfun1'.
Error in fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
Error in mez (line 11)
Ca1= fsolve(@myfun1,[Ca1_guess]);
Amnia Al-Hammadihttps://kr.mathworks.com/matlabcentral/profile/authors/17994481tag:kr.mathworks.com,2005:Question/6640232020-11-26T19:56:48Z2020-11-26T19:58:04ZHighlight cells in heatmapI created a heatmap where each cell represents a temperature value using the commands:
cdata = [values of temperature]
xvalues = [0,1,2,3,etc.]
yvalues = [0,1,2,3,etc.]
h = heatmap(xvalues,yvalues,cdata)
I need to:
command to highlight cells over a limit (for example 500)
Highlight cells within a given range (for example 300 to 800)
It is not important how the cells are highlighted, it can be a different colour (like green or blue), or a cross X on top of the cells.
Thanks for the help
Ilyass Boukharihttps://kr.mathworks.com/matlabcentral/profile/authors/17431400tag:kr.mathworks.com,2005:Question/6640282020-11-26T19:56:53Z2020-11-26T19:56:53ZSolving the Poisson Equation in 2D polar coordinates using Finite Difference MethodHi,
I am trying to solve the Poisson equation in 2D polar (r, theta) coordinates.
I am really struggling to determine this or find much research on how to do this in MATLAB, and pointers in the right direction to solving it would be greatly appreciated. I think it is quite likely that I have massively over-complicated this in my head.
I have solved it in 2D cartesian (x, y) coordinates fine, using a finite difference method and iterating using the Successive Over-Relaxation technique. But for the same equation translated to polar coordinates, the grid spaces delta r and delta theta are different values. I had assumed the cartesian grid was uniform with delta x = delta y. This means that upon discretisation, when trying to rearrange the discretised equation:
I cannot rearrange into a form Uij = ... which is how I had then used it in the FDM and SOR technique for the cartesian system.
Is there a best way of solving it in polar coordinates?
Any help would be incredibly appreciated.Sophie Malcolmhttps://kr.mathworks.com/matlabcentral/profile/authors/18864584tag:kr.mathworks.com,2005:Question/6640182020-11-26T19:51:30Z2020-11-26T19:53:26Ztransferring data element between charts in stateflowHi all
I have the above chart ... .... where Previous_stage is an input data element to the chart from the chart that preceded it and its value is one. But when reading Previous_stage inside the chart, its reading is zero .. Please what is wrongAhmad Falihhttps://kr.mathworks.com/matlabcentral/profile/authors/16934082tag:kr.mathworks.com,2005:Question/6640132020-11-26T19:51:20Z2020-11-26T19:51:20ZPower spectral density of an EEG signalHello Everyone,
I am working on a code to find the power spectral density of an EEG signal. I applied a window to the signal to reduce the spectral leakage. I compared different windows to see the window that gives the best results. However, I realize that the scale on the Y-axis (power) changes when different windows are applied. Is it supposed to happen this way. The matlab code is shown below, perhaps I missed something in the code.
load Subject_0_Rest; % Subject 0 at resting state
fs = 500; % Sampling Frequency
t = (1:length(Subject_0_Rest))/fs; % Time Vector
subplot(2,1,1);
plot(t,Subject_0_Rest); % Plot signal
nw = 50; % Filter Order
fp = 0.1; % Passband frequency
fst = 25; % Stopband frequency
wp = fp/fs/2; % Cutoff frequency
ws = fst/fs/2; % Cutoff frequency
wn = [wp,ws]; % Cutoff frequency vector(bandpass)
window = kaiser(nw+1); % Apply kaiser window
b = fir1(nw,wn,'bandpass',window); % Get filter coeff.
y = filter(b,1,Subject_0_Rest); % Filter Signal
subplot(2,1,2);
plot(t,y,'k'); % Plot filtered Signal
figure;
Y = y(1:5000); % Segment the data to 10s
Y = Y.*hann(length(Y))'; % Apply Hanning Window
N = length(Y); % Length of signal segment
P = nextpow2(N); % Pad signal to increase computational time
n = 2^P;
X = fft(Y,n); % Apply the fft algorithm
Pxx = 1/(N*fs)*abs(X(1:length(Y)/2+1)).^2; % Find signal power
f = (0:fs/N:fs/2); % Frequency Vector
Pxx(2:end-1) = 2*Pxx(2:end-1);
plot(f,10*log10(Pxx)); % Plot the power spectrum
title('Power Spectral Density Using FFT')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)')
I have attached the EEG data as well as the results I got when I applied a rectangular window and hanning window.
Thank you all in anticipationTemisanren Okotiehttps://kr.mathworks.com/matlabcentral/profile/authors/19492835tag:kr.mathworks.com,2005:Question/6640032020-11-26T19:47:31Z2020-11-26T19:47:31ZHow can I extract points from the curve in this image .PNG? Edoardo Gabrielehttps://kr.mathworks.com/matlabcentral/profile/authors/14394525