https://la.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-05-25T03:09:10Ztag:la.mathworks.com,2005:Question/5324632020-05-25T01:35:46Z2020-05-25T03:09:10ZRepetition of random numbers for variables with different lengthDear all,
My code has different loops and different algorithms and I need to get always the same or part of the same sequence of random numbers. I have been used the command rng('default') or rng(0,'twister') in several parts of the code, but, unfortunatelly, it did not work.
Basically, in order to simply, I am doing a simple code below to illustrate what I am saying:
rng(0,'twister');
s=rng();
A=lhsdesign(2,2)
rng(s)
B=lhsdesign(1,2)
The results that I got are:
A =
0.021416525878527 0.099859765555600
0.757312175638579 0.929056830686392
B =
0.873013183706494 0.086624143860981
What I should expect is B equal to the first line of A. But, it is not. Why?
Could anyone help me to solve that?
Many thanks,
Odilon.Odilon Rodrigues Filhohttps://la.mathworks.com/matlabcentral/profile/authors/5090187-odilon-rodrigues-filhotag:la.mathworks.com,2005:Question/5297882020-05-22T04:43:51Z2020-05-25T03:06:00Zmovements of the descent vehicle in the atmosphere of EarthI need help writting a Matlab script file, In the matlab I need to write the equations of motion of the space capsule that are as follows:
and I need the graph of time (x axis) vs speed (y axis).
danny crizalidhttps://la.mathworks.com/matlabcentral/profile/authors/18573210-danny-crizalidtag:la.mathworks.com,2005:Question/5322532020-05-24T19:27:42Z2020-05-25T02:58:11ZSplit Data in Character Array into MatrixI currently have a character array (~ 50000 x 1) with data "DD-MM-YY 1000 NaN NaN NaN 0.200 0.300" all in one cell, and I want to split the characters into a matrix with cells for each of the colums (i.e. col1= "DD-MM-YY" col2= 1000, etc.). However, the data in some rows are not perfectly spaced/aligned with other rows because the length of the data may be > than the length of NaN (i.e. "DD-MM-YY 1000 0.111 NaN 0.2002 0.200 0.300 ") so I cannot filter them based on character location. There is extra spacing at the end to account for this shifting (each has a length of 80). Any ideas on how I could split the data, or even how to align all the data columns?
Thanks so much! Vanessa Yauhttps://la.mathworks.com/matlabcentral/profile/authors/16150140-vanessa-yautag:la.mathworks.com,2005:Question/5324882020-05-25T02:57:05Z2020-05-25T02:57:05ZMATLAB script use in System verilog using SNPS VCS toolI have coded an algorithm using MATLAB R2019 script and i want it to be called in an System verilog file i.e The output generated by the matlab script is actually to be fed into the testbench written using SV. I dont want to use HDL coder tool as the algorithm is quite complex and re-coding it in SV/ C is quite difficult. I use synopsys VCS tool for compilation and elaboration.
My question is :
Is it possible that a MATLAB script to be called in testbench written in SV ? I've heard about DPI, but not much idea on it, or worked on it.
Can the output of the MATLAB script stored in a separate file, let's say for example a text file and i can call that file in my SV test bench.? ansuman mishrahttps://la.mathworks.com/matlabcentral/profile/authors/18591094-ansuman-mishratag:la.mathworks.com,2005:Question/5324782020-05-25T02:08:16Z2020-05-25T02:56:02ZHow can I access the numerical vector in a sym variable equation for future use in my program as a numerical value?>> syms x y
f1=2*(x^2)-(y^2)-9==0;
f1sub=isolate(f1,x);
y0=1;
x1=subs(f1sub,y,y0)
x1 =
x == (2^(1/2)*10^(1/2))/2
I want to be able to acces the numerical part of a symbolic variable, in this case "(2^(1/2)*10^(1/2))/2" for further use in the program as a numerical variable.
I would appreciate any valuable help with this issue.
Patricio Ruelas Pelayohttps://la.mathworks.com/matlabcentral/profile/authors/17509067-patricio-ruelas-pelayotag:la.mathworks.com,2005:Question/5319582020-05-24T12:08:27Z2020-05-25T02:50:45Zdraw bounding box around a characterThe code i used is
Ch = bw(boundrow(1):boundrow(end),boundcol(1):boundcol(end));
i'll get the character into the variable Ch
how can i draw a bounding box in the imageElysi Cochinhttps://la.mathworks.com/matlabcentral/profile/authors/3625227-elysi-cochintag:la.mathworks.com,2005:Question/3128122016-11-18T01:27:44Z2020-05-25T02:50:04ZCompound yearly interest with loopI'm trying to compute compound interest with loops. I'm currently using a while loop, but I don't know if that's the easiest solution. Right now, the code is producing the first year, but I can't get it to repeat more than that.
Here's the problem:
Imagine that you went to the bank and deposited $15,000 in an account that earns 7% interest every year, with each year’s interest being deposited back into the account. Write a MATLAB program that computes the number of years it would take to accumulate $400,000.
This is the code I have so far
%compute the interest of amount in bank
%initilize variable called 'prod' to 15000
initial=15000
final=0
interest=.07
while initial<40000;
final=(initial*interest)+initial
end Ryan Ellwangerhttps://la.mathworks.com/matlabcentral/profile/authors/8963252-ryan-ellwangertag:la.mathworks.com,2005:Question/4503562019-03-16T01:26:07Z2020-05-25T02:46:50ZHow can blur an imageWrite a function called blur that blurs the input image. The function is to be called like this:
output = blur(img,w);
where img, the input image is a two-dimensional matrix of grayscale pixel values between 0 and 255. Blurring is to be carried out by averaging the pixel values in the vicinity of every pixel. Specifically, the output pixel value is the mean of the pixels in a square submatrix of size 2w+1 where the given pixel sits in the center. For example, if w is 1, then we use a 3x3 matrix, that is, we average all the neighboring pixels of the given pixel and itself. Only use valid pixels when portions of the blurring matrix fall outside the image. For example, the blurred value corresponding to w = 1 at index (1,1) would be the mean of of elements (1,1), (1, 2), (2,1) and (2, 2). Both input img and output output are of type uint8.
You can download the test image here to use in MATLAB.Jorge Ortizhttps://la.mathworks.com/matlabcentral/profile/authors/7989278-jorge-ortiztag:la.mathworks.com,2005:Question/5273922020-05-20T05:18:07Z2020-05-25T02:44:49ZHow to delete multiple rows of particular values?I have a matrix of 56298 x 15. Each column has a different header such as;
'UTC, startSeconds, duration...'
I am wanting to remove entire rows (for all columns) if the 'startSeconds' is equal to or lower than 2.37.
I've tried the 'find' function but I'm concerned that will only delete the value of the cellRachael Courtshttps://la.mathworks.com/matlabcentral/profile/authors/16583973-rachael-courtstag:la.mathworks.com,2005:Question/5319932020-05-24T12:30:41Z2020-05-25T02:43:19ZBlob segmentation and writing it to folderi have segmented few blobs using the below code
ccnt = 1;
for blob = 1 : n
thisBoundingBox = measurements(blob).BoundingBox;
[new_blob, pos] = imcrop(binaryImage, thisBoundingBox);
fileName = sprintf('FolderName/%d.bmp',ccnt);
imwrite(new_blob, fileName); ccnt = ccnt + 1;
end
When using the above code, i get all the blobs, but the order of the blobs written in the folder is not as i want
If my image is
i want each segmented blob to be written in the folder in the left to right order as
but i get it as
what should i do to get it in left to right orderElysi Cochinhttps://la.mathworks.com/matlabcentral/profile/authors/3625227-elysi-cochintag:la.mathworks.com,2005:Question/5324682020-05-25T01:44:00Z2020-05-25T02:42:19ZSURF plot: Data dimensions must agree I am trying to plot the magnetic field on a rectangular surface (having x and y coordinates). Hence i have a total of 3 values x,y and B (magnetic field). I have tried plotting the surface plot using normal and transposed datasheet in excel but both of them give me the same data dimensions error. Please help me withi this. I am using the following code till now:
dataset=xlsread('import.xlsx');
x = dataset(:,1);
y = dataset(1,:)
Z = dataset(2:end,2:end)
surf(x,y,Z)
Please see the attached image for clarification.
thank youAzeem Singh Kahlonhttps://la.mathworks.com/matlabcentral/profile/authors/16158782-azeem-singh-kahlontag:la.mathworks.com,2005:Question/5324732020-05-25T01:52:37Z2020-05-25T02:38:04ZHow can I create the slider in my data range and how can my slider auto scroll until my data ends in app designer?I have a function I know the map numbers and I want the slider to change as each map number changes. Map counts vary according to years, some years 13 maps, some years 25 maps. How can I make the slider occur according to my changing map count in the APP DESIGNER? I also want this slider value to change constantly from map 1 to map 13. Thank you in advance for your help.
I would like to point out that while the map count is 13, I want the slider to be 0 to 13, and if the map count is 25, I want the slider to be 0 to 25.Özgehttps://la.mathworks.com/matlabcentral/profile/authors/11106827-ozgetag:la.mathworks.com,2005:Question/5290782020-05-21T13:29:21Z2020-05-25T02:27:25ZInput and Output GUI using GuideHello everyone,
I created a GUI to take around 12 inputs from the user then I took those inputs and stored them in variables.
Some of those variables created are based on the user's selection of a radiobutton, for example if a user selects radiobutton x I store the value 3 in a variable called m.
Example: % --- Executes on button press in radiobutton16.
function radiobutton16_Callback(hObject, eventdata, handles)
m=0
Now I would like to write a code to process those variables and perform operations on them. However every time I do that I get errors like this one:
Undefined function or variable 'a0'.
Error in Input_GUI_2>Input_GUI_2_OpeningFcn (line 59)
z=a0-b0
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in Input_GUI_2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Even though a0 is a variable created later on in the code: a0=get(handles.edit13,'string')
Can anybody please tell me what to do now?
Thanks a lot in advance.Dina Ashrafhttps://la.mathworks.com/matlabcentral/profile/authors/18567829-dina-ashraftag:la.mathworks.com,2005:Question/5324832020-05-25T02:16:00Z2020-05-25T02:16:00ZFinding set of variables that make my function approach zero I am trying to find a set of variables that make my objective function approach zero. My objective function is presented below.
-function f = rutdepth(x)
f= 0.08 - ((1 - exp(-1/6*log(x(1)/x(3))*8000))/(1/6*log(x(1)/x(3))))*x(1); (I want to make this function approach zero as close as possible if no exact solution exist)
while satisfying the following constraints
function[c, ceq] = const(x)
ceq(1)= 3877781.13- 2838712.84280904/((-log(x(1)/(33.43*x(2)*1*1.35)))^(1/0.113576473076284));
ceq(2) =3877781.13- 2838712.84280904/((-log(x(3)/(33.43*x(4)*1*1.35)))^(1/0.113576473076284));
c = [ ];
I have 4 variables x(1), x(2), x(3), and x(4). only x(1), and x(3) exist in the objective function I tried every single optimization method available, none were able to solve it. I was able to solve it in excel using evolutionary method as an option in the solver, by manipulating the seed values manually. Does anyone know how to solve it in matlab. Please any help is greatly appreciated.
rami skaffhttps://la.mathworks.com/matlabcentral/profile/authors/17521307-rami-skafftag:la.mathworks.com,2005:Question/2238082015-06-15T02:32:52Z2020-05-25T02:15:07ZHow to output optional variables in a function?Hi, I have a function where i want to either output a, b OR c given my input condition which is found in
num.
I am getting an error. Output argument "b" (and maybe others) not assigned during call.
Can you please suggest a solution!
For example,
if num=2, i want to output a=10, b=5 and if num=4, i want to output c=100
function [a,b,c] = trial_function(num)
if num==2
a=10;
b=5
else if num==4
c=100;
end
end
yashvinhttps://la.mathworks.com/matlabcentral/profile/authors/4047317-yashvintag:la.mathworks.com,2005:Question/4943192019-12-02T13:54:59Z2020-05-25T02:11:17ZDelay balancing unsuccessful because Signal rate of value inf found.Hello,
I am getting this error when generating RTL Code and IP Core at the HDL Workflow Advisor :
Delay balancing unsuccessful because Signal rate of value inf found. Offending Block:QAE_V7/Decoder/.
This message only occurs when i want to multiply a signal with a constant greater than 3. For this mulitplication I used the gain block and the product block from the HDL Code Library but there is no difference.
I already checked all blocks for an explicit sample time. Without this muliplication there is no error.Re4shttps://la.mathworks.com/matlabcentral/profile/authors/7096525-re4stag:la.mathworks.com,2005:Question/5308482020-05-23T03:50:04Z2020-05-25T02:10:38Zode45 is returning NaN while using time dependent equationsMain code defines some parameters and linear approximations for engine shutoff and stage seperation.
clear all
close all
clc
tmax=3*24*60*60;%max of three days (needed a max for the tspan in ode45)
tvec=[0 tmax];
r_moon_earth=385000*1000; %meters
r_cape=6373.3*1000; %radius at latitude, meters
om_earth=360*pi/(24*60*60*180); %radians per second
v_cape=r_cape*om_earth; %initial speed at launch pad in theta direction
lg_orbit=36500*1000; %mean orbit of lunar gateway, meters
target=r_moon_earth-lg_orbit; %target height, meters (lower of two options since its in circular orbit, saves fuel)
z0=[0 0 0 om_earth];
intpos=-5*pi/180; %guess and check
t_shutoff=300000000; %guess and check
G=6.673e-11; %Nm^2/kg^2
m_earth=5.972e24; %kg
m_falcon=1420788; %kg
m_dragon=9525; %kg
m_fuel=399161; %kg
m_moon=7.34767309e22;
om_moon=1.022; %radians per second
r_moon_earth=385000*1000; %meters
f=22819*1000; %thrust of falcon heavy, newtons
Mt=m_dragon+m_fuel+m_falcon;
Ml=m_falcon+m_fuel;
tt=linspace(0,tmax,51);
F=f*(-atan(tt-t_shutoff)+1.568486298)/(3); %approximation of thurst shut off
Tr=F.*sin(90-(10e-30).^(1./(tt)).*90); %approximation of thrust direction change
Tth=F.*cos(90-(10e-30).^(1./(tt)).*90);
M=Mt-Ml*tt.^(1/4000); %approximation for mass loss of rocket parts and fuel, kg
%equations of motion are only dependent on external forces (thrust and
%gravity) there are no constraints on the motion of the rocket
[t,y]=ode45(@(t,y)My_ODE_Function(t,y,tt,Tr,M,intpos,om_moon,r_moon_earth,G,m_moon,m_earth,Tth),tvec,z0);
The ode function code creates the equations of motion using f=ma approach dmoon is to get distance of moon form rocket and find its effect
function [ydot] = My_ODE_Function(t,y,tt,Tr,M,intpos,om_moon,r_moon_earth,G,m_moon,m_earth,Tth)
a=y(3)+intpos-om_moon*tt;
dmoon=sqrt((r_moon_earth-(y(1))^2+(2*r_moon_earth*sin(a/(2*r_moon_earth)).^2))); %distance between rocket and moon
Fge=(G*m_earth*M)/(y(1)^2); %gravitational for due to earth
Fgmr=((G*m_moon*M)./(dmoon.^2))*sin(y(3)); %gravitional forces due to moon (driection dependent)
Fgmth=-((G*m_moon*M)./(dmoon.^2))*cos(y(3));
M=interp1(tt,M,t);
Tr=interp1(tt,Tr,t);
Tth=interp1(tt,Tth,t);
Fge=interp1(tt,Fge,t);
Fgmr=interp1(tt,Fgmr,t);
Fgmth=interp1(tt,Fgmth,t);
ddr=(Tr-Fge+Fgmr)./M;
ddtheta=(Tth+Fgmth)./M;
ydot=[y(2);ddr;y(4);ddtheta];
end
ode45 is returning a vector of around 1909x4 double. the first row is actual number. The rest of the rows are NaN for all columns.
Am I missing a division by zero or is it somethign to do with the use of ode45?
Thank you very much and appreciate any help.joe jaraczhttps://la.mathworks.com/matlabcentral/profile/authors/6172915-joe-jaracztag:la.mathworks.com,2005:Question/1678442014-12-23T11:42:12Z2020-05-25T02:03:32Zhow to implement visible watermark on image in matlab ??hi , i want to algorithm to implement visible watermark in image Abdalla Mansourhttps://la.mathworks.com/matlabcentral/profile/authors/5969365-abdalla-mansourtag:la.mathworks.com,2005:Question/5319882020-05-24T12:24:09Z2020-05-25T02:00:08ZError for reading function
sumenergy=((tetha_1)*(Cp_1)*((T_isoth)-(T_1)))+ ((tetha_2)*(Cp_2)*((T_isoth)-(T_2)))+((tetha_3)*(Cp_3)*((T_isoth)-(T_3));
T_ad=350;
delta_H_T_ref=adiabatic(T_ad);
sumenergy2= ((delta_H_T_ref)+ ((delta_Cp)*((T_isoth)-(T_ref)));
In the code, the function adiabatic is working very well. But, when I call the function in sumenergy2 equality it says 'Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.' for both sumenergy and sumenergy2. What does mean this?
Özgü Dönmezhttps://la.mathworks.com/matlabcentral/profile/authors/13697940-ozgu-donmeztag:la.mathworks.com,2005:Question/5304032020-05-22T16:03:44Z2020-05-25T01:48:45ZWhy doesn't my matlab have deepNetworkQuantizer app？Why is there nothing about the quantification of the deeplearning model? But I see the official website has a lot of content in this regard, such as these：
Quantization of Deep Neural Networks
dlquantizer
calibrate
My matlab version is R2020a, win10，When I enter "deepNetworkQuantizer" in the "command window",it errors,
Unrecognized function or variable 'deepNetworkQuantizer'. ??? why
Matlab R2020a DeepLearningToolbox releasenotes does't show new quantitative features?
As you can see below, Deep Learning Toolbox has been installed.
cuihttps://la.mathworks.com/matlabcentral/profile/authors/3388605-cuitag:la.mathworks.com,2005:Question/5024042020-01-28T14:01:53Z2020-05-25T01:46:12ZError while uninstalling or re-installingHi, after downloading and installing 2019b version I tried to uninstall the 2019a version but I get the following error message:
So i tried to re-install the older version in order to "repair" the installation and then uninstall but I get the SAME error. What can I do?Elia D'Oraziohttps://la.mathworks.com/matlabcentral/profile/authors/9603295-elia-d-oraziotag:la.mathworks.com,2005:Question/2756072016-03-27T00:11:04Z2020-05-25T01:36:47ZHow do I get the workspace window back?Suddenly my workspace window has disappeared. How do I get it back? It is usually in the top right of the screen. My programming/editing, command and "files" windows are still fine, but I need to see my workspace, anybody know how to do this? Helen Kirbyhttps://la.mathworks.com/matlabcentral/profile/authors/5494713-helen-kirbytag:la.mathworks.com,2005:Question/5324582020-05-25T01:35:42Z2020-05-25T01:35:42ZBrayton-Wnet. For loop plottingHi, I'm trying to plot this for different T3 variables ( 900,1100,1300,1500,1700) in same graphs and each line should be different colour or type.
I attached the graph that ı want to plot. Please help, thank u in advance
clear;
T1=15+273;
for T3=900:200:1700
etatis=0.88;
etacis=0.88;
etayan=0.98;
etamek=0.95;
cpb=1.115;
cph=1.005;
cpg=1.147;
P1=1;
Hu=47966;
epsilony=0.02;
epsilonk=0.03;
epsilonc=0.01;
kh=1.4;
kg=1.333;
for Prc= 0:0.5:50
a=(kh-1)/kh;
b=(kg-1)/kg;
Prt=Prc*((1-epsilonk-epsilony)/(1+epsilonc));
T4=T3*(1-(etatis*(1-(1/(Prt.^0.2498)))));
T2=T1*(1+(((Prc.^0.2857)-1)/etacis));
wut=cpg*(T3-T4);
qy=(cpb*(T3-T2))/etayan;
wk=cph*(T2-T1);
wnet=wut-(wk/etamek);
etatermik=(wnet/qy);
plot(Prc,wnet,"b.-")
xlabel ('Prc', 'fontsize', [14]);
ylabel ('wnet ', 'fontsize', [14]);
grid on
hold on
end
endAlperen Koyuncuhttps://la.mathworks.com/matlabcentral/profile/authors/14642142-alperen-koyuncutag:la.mathworks.com,2005:Question/5268332020-05-19T17:05:09Z2020-05-25T01:35:26Zmatrix manipulation for color spaces. Hi , I have an image . I want to convert that to [3 3] matrix value to play with color space. I understand imead will convert image to matrix form but if I want 3 3 matrix, How should I proceed? Malini Bakthavatchalamhttps://la.mathworks.com/matlabcentral/profile/authors/17650448-malini-bakthavatchalamtag:la.mathworks.com,2005:Question/5324232020-05-24T23:43:35Z2020-05-25T01:31:40ZCreate a vector of all the even positive integers smaller than or equal to 100 in decreasing order and save it into variable evens.Does anyone know how to solve this question?Ishan Paihttps://la.mathworks.com/matlabcentral/profile/authors/16220266-ishan-paitag:la.mathworks.com,2005:Question/5261142020-05-17T12:36:12Z2020-05-25T01:31:08Zfreqresp gives wrong output for purely real inputsI am stumped by the behaviour of evalfr vs freqresp in the control systems toolbox. They claim to give the same results, but when their arguments are purely real there is a (large!) discrepancy. I am inclined to believe the results from evalfr; for all sane transfer functions a real value of s should result in a real value of the transfer function.
With the following code:
G = tf([1],[1 1]);
wc = 3+1e-10*1i;
[evalfr(G,wc);freqresp(G,wc)]
Both give the answer 0.2500-0.0000i.
When the input is purely real, however:
G = tf([1],[1 1]);
wc = 3;
[evalfr(G,wc);freqresp(G,wc)]
ans =
0.2500 + 0.0000i
0.1000 - 0.3000i
I'm using Matlab 2020a and I believe this behaviour has been around for a while; I came across an old code comment that said something like "don't use freqresp -- evalfr gives proper results here". Fine for me, but harder to advise when teaching students...Will Robertsonhttps://la.mathworks.com/matlabcentral/profile/authors/3365332-will-robertsontag:la.mathworks.com,2005:Question/5324532020-05-25T01:23:49Z2020-05-25T01:23:49ZHow can i show multiple figure in one UIaxesI want more than one figure to flow in the same app.Uiaxes window until that function ends. But all of them are working and only show the last figure on the screen. What should I do to show that the figures are flowing?
for UTCHR = 0:map-1
iUTCHR = UTCHR + 1;
tecUHR = NN(:,:,iUTCHR);
h = worldmap([min(lat) max(lat)], [min(long) max(long)]);
geoshow(app.UIAxes,h,tecUHR,R1,'DisplayType','texturemap');
load coastlines
plotm(coastlat,coastlon,'Color','black')
hold(app.UIAxes,'on')
colormap(app.UIAxes ,'jet')
colorbar(app.UIAxes)
axis equal
axis tight
title(app.UIAxes,[datestr(datenum(date(iUTCHR)) ,'yyyy-mm-dd HH:MM:SS')]);% Store the output handle
hCopy = copyobj(h.Children, app.UIAxes); % Copy all of the axis' children to your app axis
delete(h.Parent)
hold(app.UIAxes,'on')
end
Here I show the maps I call map in my figure and I want to see it move according to hourly changes. There are 25 or 13 maps for a day.Özgehttps://la.mathworks.com/matlabcentral/profile/authors/11106827-ozgetag:la.mathworks.com,2005:Question/5324282020-05-24T23:47:10Z2020-05-25T01:20:03Zobtener un area de una imagennecesito dibujar un poligono desde una imagen "x" y que permita recortar dicho poligono a otra matriz o fig, con ello poder calcular el area, perimetro, y longitudes.
las funciones que he utilizado son: impoly, drawpolygon las cuales me permiten dibujar el poligono, pero no sé como pasarla a otra fig. el impcrop no me sirve puesto que es un rectangulo que recorta la imagen
nicolas chautahttps://la.mathworks.com/matlabcentral/profile/authors/16521611-nicolas-chautatag:la.mathworks.com,2005:Question/5312132020-05-23T14:09:10Z2020-05-25T01:16:23ZHow to reduce computation timeHi,
The function "funct" takes up almost 0.06 seconds and it is the first responsible for a slow execution of an integral (more than 3 hours) when it is used in it with regards to y.
Any help please to reduce the computation time of the following function
function [out] = funct(mu,lmax,wmax,hmax,lambdab,hu,hb,y,x)
nx=length(x);
out=zeros(1,nx);
A=(mu./pi).*(wmax+lmax);
B=(mu.*wmax.*lmax)./4;
C1=(hb-(2.*hmax))./(2*hmax);
C2=(hu+hb-(2.*hmax))./(2*hmax);
for i=1:nx
S1=@(u,theta) u.*(1-exp(C1.*((A.*sqrt(u.^2+x(i).^2-(2.*x(i).*u.*cos(theta))))+B)));
S2=@(theta) (1-exp(C1.*((A.*sqrt(y.^2+x(i).^2-(2.*x(i).*y.*cos(theta))))+B)));
out(i)=lambdab.*y.*integral(S2,0,2*pi,'ArrayValued',true).*exp(-lambdab.*quad2d(S1,0,y,0,2*pi))./(1-exp(-lambdab.*quad2d(S1,0,1000,0,2*pi)));
end
endYassine Hmamouchehttps://la.mathworks.com/matlabcentral/profile/authors/18548188-yassine-hmamouchetag:la.mathworks.com,2005:Question/5317082020-05-24T03:20:50Z2020-05-25T01:12:20Zhowto organize an array into groups of n-ElementsLet's say I have a Vector of length 100
x = 1:100
and want to reshape that Vector into a 5x20 Matrix. 20 Columns with 5 Elements per Column.
a = reshape (x,5,20)
There are, then, 4 Variations of this. Starting at the 1st, 2nd, 3rd, or 4th Element.
I can group Elements 1-5 into the 1st Column, Elements 6-10 into the 2nd Column, etc.
circshift (x, -1)
b = reshape (x,5,20)
But I can also group Elements 2-6 into the 1st, 7-11 into the next, etc. The last column containing the 4 last Elements of the Vector, plus the first.
circshift (x, -2)
c = reshape (x,5,20)
I can also group Elements 3-7, 8-12, last column containing the 3 last Elements and the first 2.
circshift (x, -3)
d = reshape (x,5,20)
Then lastly 4-8, 9-13 etc.
circshift (x, -4)
e = reshape (x,5,20)
As the Order of the Columns (or Order of the Elements in the Columns) doesn't matter, circshift (x, +-5) has the same information than the original Vector x.
Is there a more Elegant Solution than circshift-ing the Vector (x) 4 times separately, and reshaping it into a matrix 4 times separately? Some function which produces from this Vector x the 4 Matrices a, b, c & d ?
I can't think of a proper title for this question, which really bugs me. Feel free to offer a suggestion.William Collantshttps://la.mathworks.com/matlabcentral/profile/authors/12904388-william-collantstag:la.mathworks.com,2005:Question/1349532014-06-17T19:22:36Z2020-05-25T01:10:45ZHow do I determine the number of headerlines in a text document?I need to read in data from a text document. The document starts with an unknown number of headerlines (zero up to 20), and the data is broken into two columns with an unknown number of rows.
4 points
PER AREA
1.000000 0.995458
0.997791 0.981313
0.988447 0.980913
0.987217 0.971326
I would like to determine the number of headerlines there are in the document, and then use textscan to skip them. My code so far is...
fileID = fopen('nameoffile.txt');
n = 0;
tline = fgetl(fileID);
while ( ischar(tline) || isinteger(tline) )
tline = fgetl(fileID);
n = n+1;
end
data = textscan( fileID, '%f%f%*[^\n]','Headerlines',n,'CollectOutput',true);
This gives me a header count, 'n', that is equal to the number of lines in the file. Is there a way to do this?
Thanks. Joshuahttps://la.mathworks.com/matlabcentral/profile/authors/3979687-joshuatag:la.mathworks.com,2005:Question/5324182020-05-24T23:43:03Z2020-05-25T01:06:42Zmaking upper case character with respect to the indexesindxC = [1,7];
s ='hello world';
i want s to be 'Hello World' with using the indxC. The indexes of c should be upper case in the string s. Can you help me thanks
Umut Oskayhttps://la.mathworks.com/matlabcentral/profile/authors/17753676-umut-oskaytag:la.mathworks.com,2005:Question/5324482020-05-25T01:05:45Z2020-05-25T01:05:45ZHelp me undersandand Frequency Vector and index vector in fourier transformI have strated learning and I am new to Matlab and fourier transform I am Struggling to understand the concept of the frequency vector and index vector in this code below. I will be grateful if someone can explain what is frequency vector (Fv) and index vector (Iv) and what the code for both at Fv, Iv and FTs_plot is doing.
L = numel(t); % Vector Length
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
FTs = fft(s)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
FTs_plot = abs(FTs(Iv))/max(abs(FTs(Iv))); % Normalised Fourier Transform
S Prohttps://la.mathworks.com/matlabcentral/profile/authors/18541726-s-protag:la.mathworks.com,2005:Question/5324432020-05-25T00:59:44Z2020-05-25T00:59:44ZContour controls in geoshowSimple question (I hope) for experienced Matlab people. But the Matlab help is no help, at least I've been unable to find it. I think I lack a generic understanding of plot control. There's a bunch of help under: https://au.mathworks.com/help/matlab/contour-plots-1.html and https://au.mathworks.com/help/matlab/ref/contour.html but I can't apply it to maps. Maybe I'm making a mistake. Maybe it's not possible.
Reading Matlab help for contours in general plots I find examples like this:
Z = peaks;
figure
[C,h] = contour(Z,8);
clabel(C,h)
====
Then the contours can be customized, using the handles(? I don't really understand handles) C & h.
But I'm using geoshow. I was doing a color plot:
geoshow(newLat, newLon, pavrainData(:,:,i)', 'DisplayType','surface') % plot % values
colormap (flipud(parula))
colorbar
caxis([camin1 camax1]) % set colorbar axis
====
In that case I have control of the scale using colormap, and caxis and that's working fine. But I want to use contours instead *and* control which contour lines are displayed, e.g 0 50 100 150 200.
1. I tried to grab handles but that doesn't work:
[C,h]=geoshow(newLat, newLon, pavrainData(:,:,i)', 'DisplayType','contour'); % plot % values
clabel(C,h)
2. I tried to include the set contours in the geoshow command (trying similar syntax to the contour command) but that doesn't work:
geoshow(newLat, newLon, pavrainData(:,:,i)', 'DisplayType','contour',[0 50 100 150 200])
Really appreciate if someone can give me guidance - is the first method (ie #1) the correct approach, or the second (#2)? Or another way? And what's the correct syntax?
Basically I just want to plot set contour lines on a map from one variable.
Thanks!Peterhttps://la.mathworks.com/matlabcentral/profile/authors/2419300-petertag:la.mathworks.com,2005:Question/5324382020-05-25T00:56:30Z2020-05-25T00:56:30Z[ERROR] Index exceeds array dimensions. Index value 0 exceeds valid range [1-19] of array stateshello im a new user on Simulink
I inserted a matlab function, this block make a model predictive torque and flux control. the output is the switching state signal for voltage source inverter.
function [sa,sb,sc] = pred(sf_ref,t_ref,wr,is,fr)
states=[0,0,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,-1,-1,0,1,1;
0,-1,0,0,0,-1,-1,-1,0,1,1,1,1,1,0,-1,-1,-1,-1;
0,-1,-1,-1,0,0,0,-1,-1,-1,-1,-1,0,1,1,1,1,1,0];
Ts=25e-6;
Rs=1.405;
Rr=1.395;
Ls=0.005839;
Lr=0.005839;
Lm=0.1722;
f=50;
Vdc=400;
xs=2*pi*f*Ls;
xr=2*pi*f*Lr;
xm=2*pi*f*Lm;
D=(xs*xr)-(xm*xm);
ts=(xr*D)/((Rs*xr^2)+(Rr*xm^2));
tr=xr/Rr;
I=[1,0;0,1];
F=(-1/ts)*I;
G1=(xm/D)*[1/tr,wr;-wr,1/tr];
K=[1,-1/2,-1/2;0,sqrt(3)/2,-sqrt(3)/2];
G2=(Vdc/3)*(xr/D)*K;
A=F*Ts;
B1=G1*Ts;
B2=G2*Ts;
gopt=10e3;
for i=1:6
v=[states(1,i);states(2,i);states(3,i)];
ispred=((A*is)+(B1*fr)+(B2*v));
sf=(B2*(D/xr)*v)-((Rs*I*Ts)*fr);
sfm=sqrt((sf(1)^2)+sf(2)^2);
Te=abs(sf(1)*ispred(2)-sf(2)*ispred(1));
g=((Te-t_ref)^2)+(sf_ref-sfm)^2;
if g<gopt
gopt=g;
end
x_opt = min(g);
if isempty(x_opt)
x_opt = 1;
end
end
sa=states(1,x_opt);
sb=states(2,x_opt);
sc=states(3,x_opt);
How to overcome this error?
Expected a value representable in the C type 'int'. Found 0.985352 instead. Error in 'MP_direct_torque_control/MATLAB Function' (line 44) sa=states(1,x_opt);
Index exceeds array dimensions. Index value 0 exceeds valid range [1-19] of array states. Error in 'MP_direct_torque_control/MATLAB Function' (line 44) sa=states(1,x_opt);novita amaliahttps://la.mathworks.com/matlabcentral/profile/authors/18230702-novita-amaliatag:la.mathworks.com,2005:Question/5324332020-05-25T00:36:57Z2020-05-25T00:48:04ZHow to get License number for online MATLAB if MATLAB is not installed?How to get License number for online MATLAB if MATLAB is not installed?Sunita Dhitalhttps://la.mathworks.com/matlabcentral/profile/authors/18593127-sunita-dhitaltag:la.mathworks.com,2005:Question/5323982020-05-24T22:59:05Z2020-05-25T00:46:36Zpixel values from Tif fileHow can I extract pixel values from this Tif file for getting the mean and std dev valuesmahesh makamhttps://la.mathworks.com/matlabcentral/profile/authors/15571608-mahesh-makamtag:la.mathworks.com,2005:Question/5212132020-04-27T22:10:12Z2020-05-25T00:37:14ZRun Matlab in a Standard User Account in OS X Catalina?I want to run Matlab as a user with a Standard Account on a MacBook Pro. I have the credentials for the administrator accout. If I try to use the graphical install while logged into the standard account then Matlab cannot access the /Applications folder even though I have typed in the administrator account name and password.
1) If I install Matlab while logged into the administrative account can I set the user to be the standard account?
2) If (1) is not possible, is there another way of installing Matlab so that I can run Matlab while logged into the standard account, i.e. without administrative privileges.
ThanksJosephhttps://la.mathworks.com/matlabcentral/profile/authors/1396652-josephtag:la.mathworks.com,2005:Question/5315882020-05-23T22:14:29Z2020-05-25T00:01:17ZNonlinear State-Space simulationHello everyone,
I have to simulate this nos linear sistem
where k0= 1x10^-4,x1, x2 and x3 are the states and u(t) is the control input.
Could you tell me plese how to simulate this system either using Matlab or Simulink?Estela Nietohttps://la.mathworks.com/matlabcentral/profile/authors/18526717-estela-nietotag:la.mathworks.com,2005:Question/5316832020-05-24T02:21:33Z2020-05-24T23:49:27ZBasic queries Matlab (vectors, indexing, construct matrices in a specific form)Hello community,
I am beginner in Matlab. I am struggling with the following exrcises. I only managed to answer 1 & 5 however the others confuse me and I don't even know how to start specially with 2 & 3. Please I need your help
My solutions:
%Exercise 1
x = [2:3:89]
%Exercise 5
function density=ExamC()
x=input('Please enter x: ');
m=input('Please enter mean: ');
s=input('Please enter standard deviation: ');
f=1/(s*sqrt(2*pi))*exp(1)^((1/2)*((x-m)/s)^2);
disp('Value of density is: '), disp(f);
end
Thank you for your help,
AbdelAbderrahmane Elakhirihttps://la.mathworks.com/matlabcentral/profile/authors/18456725-abderrahmane-elakhiritag:la.mathworks.com,2005:Question/5324132020-05-24T23:37:39Z2020-05-24T23:37:39Z[Non linear prob] "Not enough input arguments." I've created a function to call it in other script, and running the function gives me this error. The arguments in function will be created by ode45 (with the function as parameter) in the other script.function xdot=fuz(t1,x)
format long
J=0.762;m=5.25;l=0.25;B=0.2;
LL=40;E=3;w=3;G=40100;
xx = 4*pi/15;g=9.8;tal=0.71;
Ma0=m*g*l*sin(xx)+LL*exp(-E*((xx)+(pi/2)))*(xx+pi/2-w);
x=[x(1); x(2); x(3)];
f21=(1/J)*(-m*g*l(x(1)+xx)-LL*exp(-E+xx+pi/2)*(x(1))+Ma0);
F1=[-0.5 0.9 0.015];
F2=[-2.3 4.3 0.01];
u=-x*(F1*mi1+F2*mi2);
A1=[0 1 0; -12.524 (-B/J) 1/J; 0 0 -1/tal];
A2=[0 1 0; -26.523 (-B/J) 1/J; 0 0 -1/tal];
B1=[0 0 (G/tal)]';
B2=[0 0 (G/tal)]';
xdot=mi1*(A1*x+B1*u)+mi2*(A2*x+B2*u);
end
The script that call function
clear all
J=0.762;m=5.25;l=0.25;B=0.2;
LL=40;E=3;w=3;G=40100;
xx = 4*pi/15;g=9.8;tal=0.71;
Ma0=m*g*l*sin(xx)+LL*exp(-E*((xx)+(pi/2)))*(xx+pi/2-w);
[t1,x]=ode45('fuz',[0 3],[-4*pi/15; 0 ;-Ma0]);
x1=x(:,1);
x2=x(:,2);
x3=x(:,3);
a21a=-12.524
a21b=-26.523
for i=1:length(t1)
f21(i)=(1/J)*(-m*g*l(x1(i)+xx)-LL*exp(-E+xx+pi/2)*(x1(i))+Ma0);
mi_1(i)=(f21(i)-a21b)/(a21a-a21b);
mi_2(i)=(f21(i)-a21a)/(a21b-a21a);
mi1=mi_1(i); mi2=mi_2(i);
F1=[-0.5 0.9 0.015];
F2=[-2.3 4.3 0.01];
x_is=[x(i,1);x(i,2);x(i,3)];
u(i)=-x_is*(F1*mi1*+F2*mi2);
P(i)=u(i)+(Ma0/G)
end
tetav=x1(1:length(t1))+4*pi/15;
Ma=x3(1:length(t1))+Ma0;
%PLOTS
subplot(2,2,1)
plot(t1(1:length(t1)),tetav)
subplot(2,2,2)
plot(t1(1:length(t1)),x2(1:length(t1)))
subplot(2,2,3)
plot(t1(1:length(t1)),Ma)
subplot(2,2,4)
plot(t1(1:length(t1)),P)
The error:
Not enough input arguments.
x=[x(1); x(2); x(3)];
Comenting 'x' in function returns me another error in f21. Olat Javihttps://la.mathworks.com/matlabcentral/profile/authors/18592887-olat-javitag:la.mathworks.com,2005:Question/5323282020-05-24T21:00:17Z2020-05-24T23:37:37ZError using reshape To RESHAPE the number of elements must not change.Can someone help me with this error. I attempted to use numel to fix it but was not able to get a clear response.Charles sunhttps://la.mathworks.com/matlabcentral/profile/authors/16014625-charles-suntag:la.mathworks.com,2005:Question/4835432019-10-04T05:17:21Z2020-05-24T23:31:00Z[Assignment]Write a function called saddle that finds saddle points in the input matrix M. Write a function called saddle that finds saddle points in the input matrix M. For the purposes of this problem, a saddle point is defined as an element whose value is greater than or equal to every element in its row, and less than or equal to every element in its column. Note that there may be more than one saddle point in M. Return a matrix called indices that has exactly two columns. Each row of indices corresponds to one saddle point with the first element of the row containing the row index of the saddle point and the second element containing the column index. If there is no saddle point in M, then indices is the empty array.
I am working on this assignment...but i got error feedback all the time,i'm still a noob,so can anyone help me to figure out what is wrong in my program? how to improve it?
Here is my program
function indices = saddle(M)
[a,~] = size(M);
j = 1;i = 1;
[max_M,~] = max(M,[],2);
count = 0;
for ii = 1:a
[c,d] = find(M==max_M(ii));
[e,f] = size(c);
mi = min(M(:,d));
if(max_M(ii) == mi)
while i<=f
while i<=e
output(j,1) = c(i);
output(j,2) = d(i);
j = j+1;
i = i+1;
count = count+1;
end
end
end
if count>0
indices = output;
else
indices = [];
end
end
endYihan Liuhttps://la.mathworks.com/matlabcentral/profile/authors/16299961-yihan-liutag:la.mathworks.com,2005:Question/2656932016-01-29T05:22:35Z2020-05-24T23:28:14ZHow to use light-emitting diode and photodiode together?When I connect light-emitting diode (port W) to photodiode (Port D) in simulink, errors will occur. It says 'Invalid Physical Signal connection at port 'W'. Source unit is 'W' and destination unit is 'W/m^2''' What do I need to insert between light-emitting diode and photodiode? Thanks!marin kennyhttps://la.mathworks.com/matlabcentral/profile/authors/7587571-marin-kennytag:la.mathworks.com,2005:Question/5307282020-05-22T23:25:17Z2020-05-24T23:24:06ZSolve/fsolve system of equations with exp, and multiple variables.Hello, wanted to solve system of equations, but cant solve and fsolve don't give answers. Solve:
clc
clear all
syms t tf x(t) x1(t) x1_(t) x2(t) x2_(t) L1(t) L2(t) L1_(t) L2_(t) u(t) u_(t) m k c f x1x2(t) S(t) eq_u(t) L1L2(t) eq_u_C(t) x_C(t) d_H_tf_C(t);
F1=subs(x2_+c/m*x2+k/m*x1,[c k m],[2 10 1])
H=subs(u^2+L1*x2+L2*(-k/m*x1-c/m*x2+u),[c k m],[2 10 1])
H1=subs(H,[x1_ x2_ L1_ L2_],[diff(x1,t) diff(x2,t) diff(L1,t) diff(L2,t)])
F=subs(F1,[x1 x1_ x2 x2_],[x diff(x,t) diff(x,t) diff(x,t,2)])
S=0
d_H_x1=subs(subs(diff(subs(H,x1(t),f),f),f,x1(t)),[x1 x1_ x2 x2_],[x diff(x,t) diff(x,t) diff(x,t,2)])
d_H_x2=subs(subs(diff(subs(H,x2(t),f),f),f,x1(t)),[x1 x1_ x2 x2_],[x diff(x,t) diff(x,t) diff(x,t,2)])
d_H_u=subs(subs(diff(subs(H,u(t),f),f),f,u(t)),[x1 x1_ x2 x2_],[x diff(x,t) diff(x,t) diff(x,t,2)])
d_H_tf(t)=subs(diff(S,t)+H,[x1 x1_ x2 x2_],[x diff(x,t) diff(x,t) diff(x,t,2)])
eq_u(t)=solve(subs(d_H_u,u,f)==0,f)
L1L2=dsolve([d_H_x1==-diff(L1,t) d_H_x2==-diff(L2,t)])
eq_u_C(t)=subs(eq_u,[L1 L2],[L1L2.L1 L1L2.L2])
x_C(t)=dsolve(F==eq_u_C)
d_H_tf_C(t)=subs(d_H_tf,[u L1 L2],[eq_u_C L1L2.L1 L1L2.L2])
C1234=solve([d_H_tf_C(tf)==0 x_C(0)==3 x_C(tf)==3 subs(diff(x_C,t),t,0)==0 subs(diff(x_C,t),t,tf)==0])
solve: Unable to find explicit solution.
Also trying fsolve:
function F = myfun(x)
F=[((x(1)*cos(3*x(5))*exp(x(5)))/2 - (x(2)*sin(3*x(5))*exp(x(5)))/2)^2 + (x(1)*(cos(3*x(5))*exp(x(5)) + 3*sin(3*x(5))*exp(x(5))) + x(2)*(3*cos(3*x(5))*exp(x(5)) - sin(3*x(5))*exp(x(5))))*diff(x(x(5)), x(5)) - (x(1)*cos(3*x(5))*exp(x(5)) - x(2)*sin(3*x(5))*exp(x(5)))*(10*x(x(5)) + 2*diff(x(x(5)), x(5)) + (x(1)*cos(3*x(5))*exp(x(5)))/2 - (x(2)*sin(3*x(5))*exp(x(5)))/2);x(3) - (3*x(2))/80 - x(1)/80 - 3;x(3)*cos(3*x(5))*exp(-x(5)) - (sin(3*x(5))*exp(x(5))*(10*x(1) + x(1)*cos(6*x(5)) + 3*x(2)*cos(6*x(5)) + 3*x(1)*sin(6*x(5)) - x(2)*sin(6*x(5))))/240 - x(4)*sin(3*x(5))*exp(-x(5)) + (cos(3*x(5))*exp(x(5))*(x(2)*cos(6*x(5)) - 3*x(1)*cos(6*x(5)) - 10*x(2) + x(1)*sin(6*x(5)) + 3*x(2)*sin(6*x(5))))/240 - 3;- x(1)/8 - x(3) - 3*x(4) ;x(4)*sin(3*x(5))*exp(-x(5)) - (sin(3*x(5))*exp(x(5))*(x(2)*cos(6*x(5)) - 3*x(1)*cos(6*x(5)) - 10*x(2) + x(1)*sin(6*x(5)) + 3*x(2)*sin(6*x(5))))/80 - x(3)*cos(3*x(5))*exp(-x(5)) - 3*x(4)*cos(3*x(5))*exp(-x(5)) - 3*x(3)*sin(3*x(5))*exp(-x(5)) - (sin(3*x(5))*exp(x(5))*(10*x(1) + x(1)*cos(6*x(5)) + 3*x(2)*cos(6*x(5)) + 3*x(1)*sin(6*x(5)) - x(2)*sin(6*x(5))))/240 + (cos(3*x(5))*exp(x(5))*(6*x(1)*cos(6*x(5)) + 18*x(2)*cos(6*x(5)) + 18*x(1)*sin(6*x(5)) - 6*x(2)*sin(6*x(5))))/240 + (sin(3*x(5))*exp(x(5))*(6*x(2)*cos(6*x(5)) - 18*x(1)*cos(6*x(5)) + 6*x(1)*sin(6*x(5)) + 18*x(2)*sin(6*x(5))))/240 - (cos(3*x(5))*exp(x(5))*(10*x(1) + x(1)*cos(6*x(5)) + 3*x(2)*cos(6*x(5)) + 3*x(1)*sin(6*x(5)) - x(2)*sin(6*x(5))))/80 + (cos(3*x(5))*exp(x(5))*(x(2)*cos(6*x(5)) - 3*x(1)*cos(6*x(5)) - 10*x(2) + x(1)*sin(6*x(5)) + 3*x(2)*sin(6*x(5))))/240 ]
end
with
x0=[2;2;2;2;2]
options = optimoptions('fsolve','Display','iter');
[x,fval]=fsolve(@(x) myfun(x),x0,options)
but gets errors:
Array indices must be positive integers or logical values.
Error in myfun (line 9)
F=[((x(1)*cos(3*x(5))*exp(x(5)))/2 - (x(2)*sin(3*x(5))*exp(x(5)))/2)^2 + (x(1)*(cos(3*x(5))*exp(x(5)) + 3*sin(3*x(5))*exp(x(5))) + x(2)*(3*cos(3*x(5))*exp(x(5)) - sin(3*x(5))*exp(x(5))))*diff(x(x(5)), x(5)) - (x(1)*cos(3*x(5))*exp(x(5)) - x(2)*sin(3*x(5))*exp(x(5)))*(10*x(x(5)) + 2*diff(x(x(5)), x(5)) + (x(1)*cos(3*x(5))*exp(x(5)))/2 - (x(2)*sin(3*x(5))*exp(x(5)))/2);x(3) - (3*x(2))/80 - x(1)/80 - 3;x(3)*cos(3*x(5))*exp(-x(5)) - (sin(3*x(5))*exp(x(5))*(10*x(1) + x(1)*cos(6*x(5)) + 3*x(2)*cos(6*x(5)) + 3*x(1)*sin(6*x(5)) - x(2)*sin(6*x(5))))/240 - x(4)*sin(3*x(5))*exp(-x(5)) + (cos(3*x(5))*exp(x(5))*(x(2)*cos(6*x(5)) - 3*x(1)*cos(6*x(5)) - 10*x(2) + x(1)*sin(6*x(5)) + 3*x(2)*sin(6*x(5))))/240 - 3;- x(1)/8 - x(3) - 3*x(4) ;x(4)*sin(3*x(5))*exp(-x(5)) - (sin(3*x(5))*exp(x(5))*(x(2)*cos(6*x(5)) - 3*x(1)*cos(6*x(5)) - 10*x(2) + x(1)*sin(6*x(5)) + 3*x(2)*sin(6*x(5))))/80 - x(3)*cos(3*x(5))*exp(-x(5)) - 3*x(4)*cos(3*x(5))*exp(-x(5)) - 3*x(3)*sin(3*x(5))*exp(-x(5)) - (sin(3*x(5))*exp(x(5))*(10*x(1) + x(1)*cos(6*x(5)) + 3*x(2)*cos(6*x(5)) + 3*x(1)*sin(6*x(5)) - x(2)*sin(6*x(5))))/240 + (cos(3*x(5))*exp(x(5))*(6*x(1)*cos(6*x(5)) + 18*x(2)*cos(6*x(5)) + 18*x(1)*sin(6*x(5)) - 6*x(2)*sin(6*x(5))))/240 + (sin(3*x(5))*exp(x(5))*(6*x(2)*cos(6*x(5)) - 18*x(1)*cos(6*x(5)) + 6*x(1)*sin(6*x(5)) + 18*x(2)*sin(6*x(5))))/240 - (cos(3*x(5))*exp(x(5))*(10*x(1) + x(1)*cos(6*x(5)) + 3*x(2)*cos(6*x(5)) + 3*x(1)*sin(6*x(5)) - x(2)*sin(6*x(5))))/80 + (cos(3*x(5))*exp(x(5))*(x(2)*cos(6*x(5)) - 3*x(1)*cos(6*x(5)) - 10*x(2) + x(1)*sin(6*x(5)) + 3*x(2)*sin(6*x(5))))/240 ]
Error in cw7>@(x)myfun(x)
Error in finDiffEvalAndChkErr
Error in finitedifferences
Error in computeFinDiffGradAndJac
Error in levenbergMarquardt (line 100)
[JAC,~,~,numEvals,evalOK] = computeFinDiffGradAndJac(XOUT,funfcn,confcn,costFun, ...
Error in fsolve (line 417)
levenbergMarquardt(funfcn,x,verbosity,options,defaultopt,f,JAC,caller, ...
Error in cw7 (line 28)
[x,fval]=fsolve(@(x) myfun(x),x0,options)RobaczeQhttps://la.mathworks.com/matlabcentral/profile/authors/18580253-robaczeqtag:la.mathworks.com,2005:Question/5324032020-05-24T23:07:46Z2020-05-24T23:19:57Zmatrix dimensions must agree errorHello guys, I am trying to do this problem, but ı get matrix dimensions must agree error. Can you please help me with that?
a=0;
b=4;
ca=1;
cb=-3;
a1=@(x) 0.*x;
a0=@(x) (1+x);
g=@(x) 1-x.^2;
h=0.01;
N=round((b-a)/h);
x=linspace(a,b,N+1);
x=x';
G=g(x);
K=1/h^2*(2.*diag(ones(1,N+1))-diag(ones(1,N)-1)-diag(ones(1,N),1)); % heres the error 'Matrix dimensions must agree.'
A=diag(a0(x));
A(1,1)=0;
A(end,end)=0;
A1=a1(x);
B=1/(2*h)*(diag(A1(1:end-1),1)-diag(A1(2:end),-1));
B(1,2)=0;
B(end,end-1)=0;
G(1)=ca;
G(end)=cb;
K(1,1)=1;
K(1,2)=0;
K(end,end-1)=0;
K(endd,end)=1;
y=(K+B+A)\G;Alicia Ghttps://la.mathworks.com/matlabcentral/profile/authors/13565959-alicia-gtag:la.mathworks.com,2005:Question/5324082020-05-24T23:11:48Z2020-05-24T23:13:10ZAdd datetime vector which contains NaT to doubleI have a 2546x7200 matrix and I would like to add a vector of datetimes to the first column. The first row of the matrix is frequency values, the first column would be datetimes, and the cells filled with decibel values. However, since the first row of the datetime vector is NaT, I get an error when I try to append it. How could I overcome this? Thanks!
I tried:
A=cat(2,t,output_plot);
%where t is datetime vector and output_plot is the double matrix
Louise Wilsonhttps://la.mathworks.com/matlabcentral/profile/authors/14092323-louise-wilsontag:la.mathworks.com,2005:Question/5320982020-05-24T15:32:32Z2020-05-24T23:09:39ZHow to update the PDE toolbox with the real measurement?Hi,
I am working on a structural analysis with the PDE toolbox. I would like to update (or change) the value (displacement of a certain point) at a certain time (or at every iteration) during the simulation process? Does anyone know if the pde toolbox can realize this? Do I need to write a function file when defining the load condition?
Thank you so much.
KunKun Zenghttps://la.mathworks.com/matlabcentral/profile/authors/9947596-kun-zengtag:la.mathworks.com,2005:Question/5299032020-05-22T08:03:19Z2020-05-24T23:07:38ZWhy does probabililty distribution for 3D matrix not work with NaN values? Hi,
I am trying to calculate the critical probability for each grid point in a 3D matrix. To do so I have some sample data, calculated a test statistic and tested with a small sample to calculate the probability distribution and critical probability (all worked fine). Now I tried the same for the whole dataset (all grid points) and it won't work anymore, the code seems to stop when there are NaN values. My plan is to perform the calculation for each data point along the third dimension and skip each grid point, which is filled with NaN. This is where I am stuck now! I have tried several ways to omit NaNs but it doesn't seem to work.
This is the part of my code:
%% 2) calculate critical probability (lambda) for each grid point
f = zeros(size(U_stat,1),size(U_stat,2),100);
xi = zeros(size(U_stat,1),size(U_stat,2),100);
lambda_x_neg= zeros(size(U_stat,1),size(U_stat,2));
lambda_x_pos=zeros(size(U_stat,1),size(U_stat,2));
nonanlocs = ~isnan(U_stat);
for i = 1: size(U_stat,1)
for j = 1:size(U_stat,2)
[f(nonanlocs(i,j,:)),xi(nonanlocs(i,j,:))]=ksdensity(squeeze(U_stat(nonanlocs(i,j,:))));
% then calculate critical value lambda x for each grid point
lambda_x_neg(i,j) = xi(i,j,(find(f(i,j,:)<=0.05 & xi(i,j,:)<=0,1,'last')));
lambda_x_pos(i,j) = xi(i,j,(find(f(i,j,:)<=0.05 & xi(i,j,:)>0,1,'first')));
end
end
Many thanks for your help in advance!Hanna Hhttps://la.mathworks.com/matlabcentral/profile/authors/18001512-hanna-htag:la.mathworks.com,2005:Question/3829812018-02-15T23:33:47Z2020-05-24T23:03:06ZUsing custom wavelets for inverse transform?I'd like to use a custom wavelet to perform a cwt over a specified frequency range, then do the icwt back. Since the new version of cwt() doesn't take custom wavelets, I've been playing with the old version, and got the cwt part to work. But it doesn't seem like there's any old version of icwt that would accept a custom wavelet. Is there one that I am not aware of? If not, how difficult would it be to manually reconstruct a signal from the output of the old cwt() command?Asa Stahlhttps://la.mathworks.com/matlabcentral/profile/authors/11883676-asa-stahl