https://es.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-07-04T13:11:45Ztag:es.mathworks.com,2005:Question/5594002020-07-04T12:42:38Z2020-07-04T13:11:45ZCreate custom x-axis for 'imagesc' plotI am trying to create a custom x-axis for my imagesc plot using a separate vector ('xaxis') with increasing values from -150.36 to 265.8773.
However, I am facing an issue where when I set this vector as my x-axis, it appears only for half of the image. The vector 'xaxis' has the same length as the x-axis pixels in the image and I would like it's values to represent each x-axis pixel rather than the default which only has the pixel value listed.
My intention is to then evenly space out the x-axis ticks using the label command after setting the x-axis to 'xaxis' to avoid overwriting/bunching together.
Original x-axis;
x-axis from vector 'xaxis':
From the image, I understand that the ticks only go to half the image before starting over and overwriting the previous ticks.
Any tips would be highly appreciated.
Below is my code for setting the x-axis to the desired tick values;
colormap gray;
%subplot(2,2,1);
imagesc(inclinedCyl_d20);
ax = gca;
ax.XTick = [xaxis];Kevin Mutaihttps://es.mathworks.com/matlabcentral/profile/authors/18691029-kevin-mutaitag:es.mathworks.com,2005:Question/5594182020-07-04T13:10:57Z2020-07-04T13:10:57Zartificial synthetic EEG dataCan some one send me the matlab code to generate 'synthetic eeg data' in matlab. Plz send it on my mail (soham.yadav16@gmail.com). I need this code for my project.Soham Yadavhttps://es.mathworks.com/matlabcentral/profile/authors/18529572-soham-yadavtag:es.mathworks.com,2005:Question/5594152020-07-04T13:08:04Z2020-07-04T13:08:04ZCompute the first 5 components of the exponential Fourier series for the waveform shown below. Assume ω=1 rad/s and U= 1 V. Verify your answer using matlab or simulink.Compute the first 5 components of the exponential Fourier series for the waveform shown below.
Assume ω=1 rad/s and U= 1 V. Verify your answer using matlab or simulinkjean komquatehttps://es.mathworks.com/matlabcentral/profile/authors/18913269-jean-komquatetag:es.mathworks.com,2005:Question/5588842020-07-03T08:51:18Z2020-07-04T13:03:08ZHow can I save UIAxes as an image when button is pushed in app designer?How can I save UIAxes as an image when button is pushed in app designer?
newfigure = figure;
copyobj(app.UIAxes, newfigure);
hgsave(newfigure, 'testFIgure.fig');
I tried this but it gives me an error.Yaren Severhttps://es.mathworks.com/matlabcentral/profile/authors/15756083-yaren-severtag:es.mathworks.com,2005:Question/5592772020-07-04T05:03:33Z2020-07-04T13:02:54ZHow to solve this fourier series/ boundary value on matlab?Can anyone tell me how to compute this on matlab? show the codes in step etc...
Suhayl Mlbhttps://es.mathworks.com/matlabcentral/profile/authors/18911145-suhayl-mlbtag:es.mathworks.com,2005:Question/5594122020-07-04T13:02:33Z2020-07-04T13:02:33ZMatlab Curve Fitting Costumed EquationHi, I want to write the following custom equation in the Maltb Curve Fitting Tool
f(x)=f(x-1)+x^b
However I am not able to include the f(x-1) term in the equation box.
Need HelpMridul Sannyalhttps://es.mathworks.com/matlabcentral/profile/authors/8471347-mridul-sannyaltag:es.mathworks.com,2005:Question/5577642020-07-01T13:04:45Z2020-07-04T13:01:58Zall test harness signals are initialized to the wrong values (ZEROS)Issue: When i create a test harness for a specific subsystem, all the subsystem input ports signals shows up initialized to ZEROS in the test sequence - wrong initialization. I know i can change these initialization statements manually, but the system under test has more than a 100 signals which makes it tedious.
In the model, these signals are each associated with Simulink.Signal object where each initialized to a specific InitialValue. Note that the test sequence was able to the pull the datatype information for each signal from the workspace definition that is enforced by the non-virtual bus definition. refer to below as an example:
% SIGNALS OBJECTS
<SignalName> = Simulink.Signal;
<SignalName>.CoderInfo.StorageClass = 'ExportedGlobal';
<SignalName>.CoderInfo.Alias = '';
<SignalName>.CoderInfo.Alignment = -1;
<SignalName>.Description = '';
<SignalName>.DataType = 'auto';
<SignalName>.Min = [];
<SignalName>.Max = [];
<SignalName>.DocUnits = '';
<SignalName>.Dimensions = -1;
<SignalName>.DimensionsMode = 'auto';
<SignalName>.Complexity = 'real';
<SignalName>.SampleTime = -1;
<SignalName>.InitialValue = '1';
% BUS OBJECTS
elems(3) = Simulink.BusElement;
elems(3).Name = 'SignalName';
elems(3).Dimensions = 1;
elems(3).DimensionsMode = 'Fixed';
elems(3).DataType = 'boolean';
elems(3).SampleTime = -1;
elems(3).Complexity = 'real';
elems(3).Min = [];
elems(3).Max = [];
elems(3).DocUnits = '';
elems(3).Description = '';
how do I make test harness to pull/adopt the intial value information for each signal defined in the workspace upon its creation and set them in the initialization step of the test sequence.
Any help is appreciated; thank you in advance!Yamenhttps://es.mathworks.com/matlabcentral/profile/authors/3671530-yamentag:es.mathworks.com,2005:Question/5594092020-07-04T13:01:31Z2020-07-04T13:01:31ZIs stackedplot compatible with matlab2tikz ?I want to create plots with Stackedplot with Multiple Variables Using One Y-Axis and then transfer it to tex. Matlab2tikz worked for subplot. Now when I save it as a figure and use matlab2tikz no output data is shown in the tikz file. Can you even use it for this?Dominika Thiedehttps://es.mathworks.com/matlabcentral/profile/authors/15468673-dominika-thiedetag:es.mathworks.com,2005:Question/5594062020-07-04T13:01:18Z2020-07-04T13:01:18ZSave Function and uisave are not working properly.Can you please tell me why the following codes are not working?
The functional form of save is not working right, especially when I am trying to specify a name of the file while saving it.
I have tried to extract the filenames from the user defined names using the following code.
Filename = Name(~isspace(Name));
Then I have tried using the following codes to save the file.
Filename = [Filename{:} '.mat'];
uisave({Name, x, y ,z}, Filename);
Another way I tried...
save(Filename, {Name, x, y, z});
The save function is working when the filename specified is static such as
save('all_variables.mat', {Name, x ,y ,z});
Please tell me what am I doing wrong here. What should I do to save the variables along with the user specified dynamic names? And why am I getting an error message in the above pictures? Should it not be saving the variables dynamically instead of showing an error message dialog box?Sheran Bhattacharyyahttps://es.mathworks.com/matlabcentral/profile/authors/14439962-sheran-bhattacharyyatag:es.mathworks.com,2005:Question/5585022020-07-02T15:02:12Z2020-07-04T12:59:09ZAbout "eigs" functionHello every one,
I want to run an LLE code when I need to use "eigs" function to solve an eigenproblem.
This is the syntax that I use in Matlab Online :
[YT, ~] = eigs(M, d+1, 0, 'Display', 0, 'StartVector', ones(size(M, 1), 1));
The problem is that I obtain a new result each time the code is executed.
If you can help me to overcome this problem ?
Best regards,
Achraf EL OMARIhttps://es.mathworks.com/matlabcentral/profile/authors/18902418-achraf-el-omaritag:es.mathworks.com,2005:Question/5589292020-07-03T10:40:14Z2020-07-04T12:57:22Zstack up 3D images into a 4D matrixHello,
I have multiple 3D images and I should stack up these images into a 4D matrix and use it as an input for another code for feature extraction. I have tested this method : cat(4,im1,im2,im3) but it doesn't work well as input. How can I convert these images into 4D matrix ? SaHaRhttps://es.mathworks.com/matlabcentral/profile/authors/11317038-sahartag:es.mathworks.com,2005:Question/5593852020-07-04T11:47:24Z2020-07-04T12:51:29ZHow to plot (n) circles with known center and radius Hi,
I need to generat a plot of (n) circles. The radius of the circles is known and equals to 15m. The circles centers are separated by azimuthal angle equal to 10 degrees and they are located on the perimiter of biggr circle that it is radius is 120m.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
theta=10 % azimuthal distance between the centers of circles group
r=120 % The radius of the big circle
DM=12 % The radius of the group of circles
for i=1:38 % number of circles
x1(i)= r*cosd(90-(i-1)*theta); % the x comoenets of the circle group
y1(i)=r*sind(90-(i-1)*theta); % The y component of the circle group
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Would please advise.
Best Regards,Abdul Hamed Hatemhttps://es.mathworks.com/matlabcentral/profile/authors/14610896-abdul-hamed-hatemtag:es.mathworks.com,2005:Question/5565552020-06-29T12:14:08Z2020-07-04T12:49:48Zcoefficient determination of two variablesHello everyone,
I would like to ask you some guidelines about how to solve this equation in matlab. This is an equation for an admittance of the open ended coaxial probe.
I would like to find the coefficients $\alpha$ and $\beta$ in the equation based on my measured data, in which those parameters are known: $\epsilon_r$, s, a and Y. The upper bound (N,M,P,Q) we can choose. For example, N=M = 4; P=Q=8.
I think some kind of fitting function might address my question, but I am really new to Matlab and have no ideas to do that.
Thank you very much,
GreetingsDuy Hai Nguyenhttps://es.mathworks.com/matlabcentral/profile/authors/12153236-duy-hai-nguyentag:es.mathworks.com,2005:Question/5594032020-07-04T12:45:22Z2020-07-04T12:45:22ZFind the value of aI am trying to solve this in MATLAB.
Find the value of the number a such that the families of curves y = (x + c)-1 and y= a (x + k)1/3 are orthogonal trajectories.
Here are the steps I took to solve the problem however I can't figure out how to do this in MATLAB.
Step 1.
y’= -1(x + c)-2(1) = -1(1 / (x + c)2
Step 2.
y’= - 1/(x0+c)2
Step 3.
y’= a/3 (x + k)-2/3 (1) = a / 3(x + k)2/3
Step 4.
y’= a/ 3(x0+k)2/3
Step 5
y = a(-k+k)1/3 = a(0) = 0
Step 6
(- 1/(x0+c)2) (a/3(x0+k)2/3) = -1, a = 3(x0+c)2(x0+k)2/3
Step 7
(x0+c)-1= a(x0+k)1/3, 1/(x0+c) = a(x0+k)1/3, (x0+c) = 1/a(x0+k)1/3
Step 8
a = 3(1/a(x0+k)1/3)2(x0+k)2/3
a = 3(1/a2(x0+k)2/3) (x0+k)2/3
a = 3(1/a2)
a3 = 3 a = 3sqrt(3)Trenton Rougeauhttps://es.mathworks.com/matlabcentral/profile/authors/18897225-trenton-rougeautag:es.mathworks.com,2005:Question/5590342020-07-03T15:18:23Z2020-07-04T12:45:08ZHow can I count scatter data surrounded by shapes?How can I count how many pieces of data are wrapped around a particular shape?
I drew a shape and scattered the data on it.
The data of figures are RH2 and AT2.
The scatter data are humid1 and temp1.
How can I count scatter data surrounded by shapes?
I need expert help.
Thank you.
attachment : datas, m-file and image
Changho LEEhttps://es.mathworks.com/matlabcentral/profile/authors/14352750-changho-leetag:es.mathworks.com,2005:Question/5593432020-07-04T09:58:37Z2020-07-04T12:42:37ZFinding min and max of ODEsThe task was to model an enzymatic reaction which I did with the written code. The obtained plot and the equations are in the attached picture. I need to find the the time when the enzyme concentration is minimal and enzyme-substrate concentration maximal. I know that the concentration change in the minimum/maximum should be zero ( d[E]/dt=d[C]/dt=0 ) but I don't know how I would write the code to find the time.
function dydt = reaction(~, cse)
% Defining reaction parameters:
k1 = 6;
k2 = 1;
kminus1 = 2;
% Defining reactions
reaction=zeros(4,1);
reaction(1) = k1*cse(2)*cse(3)-kminus1*cse(1)-k2*cse(1);
reaction(2) = -k1*cse(2)*cse(3)+kminus1*cse(1);
reaction(3) = -k1*cse(2)*cse(3)+kminus1*cse(1)+k2*cse(1);
reaction(4) = k2*cse(1);
dydt=[reaction(1); reaction(2); reaction(3); reaction(4)];
end
_____
% defining the time range:
T=12;
trange=[0 T];
% defining initial values (concentrations) for c,s,e i p:
cs0 = [0; 1; 1; 0];
% [t,x] = ode45(@reaction, trange, initial values)
[t,unknown]=ode45(@reaction,trange,cs0);
c = unknown(:, 1);
s = unknown(:, 2);
e = unknown(:, 3);
p = unknown(:, 4);
% plot drawing
plot(t,c,'m',t,s,'c',t,e,'r',t,p,'k')
ylim([0 1.1])
xlabel('time, t')
ylabel('concentration')
legend({' enzyme-substrate complex concentration',' substrate concentration',' enzyme concentration ',' product concentration'}, "Location","best")Sarahttps://es.mathworks.com/matlabcentral/profile/authors/18862670-saratag:es.mathworks.com,2005:Question/5593222020-07-04T08:22:38Z2020-07-04T12:37:44Zfitting a circle with fitnlm Hello, I tried to fit following data to a circle with help of fitnlm
i used following circle function to determine the center of the circle and the radius:
X = readmatrix('coordinates.txt') %you can find the coordinats.txt in the attachments
circlefun = @(X, b) (X(:,1).^2 + X(:,2).^2 + b(1)*X(:,1) + b(2)*X(:,2) + b(3));
y = zeros(length(X(:,1)),1);
beta0 = [0 0 400];
mdl = fitnlm(X,y,circlefun, beta0)
it gives me following output:
Error using nlinfit (line 219)
MODELFUN must be a function that returns a vector of fitted values the same size as Y (1000-by-1). The model function you provided returned a result that was 1-by-1.
One common reason for a size mismatch is using matrix operators (*, /, ^) in your function instead of the corresponding elementwise operators (.*, ./, .^).
Error in NonLinearModel/fitter (line 1127)
nlinfit(X,y,F,b0,opts,wtargs{:},errormodelargs{:});
Error in classreg.regr.FitObject/doFit (line 94)
model = fitter(model);
Error in NonLinearModel.fit (line 1434)
model = doFit(model);
Error in fitnlm (line 99)
model = NonLinearModel.fit(X,varargin{:});
What I already tried: I used Newton Method for multivariables and the results were quite good in my opinion, but i would like to understand how i can use fitnlm.
Thanks in advance!Hoschang Noorihttps://es.mathworks.com/matlabcentral/profile/authors/18517365-hoschang-nooritag:es.mathworks.com,2005:Question/5591632020-07-03T19:52:27Z2020-07-04T12:35:15ZEliminating nested loops without repeating input combinations for equation outputHi,
I have been given an equation with several variables. For each variable I have created a normal distribution using normn. I would like to get all the solutions to the equation using every single possible combination of values without them repeating themselves. Since I want to use distribution fitter and fit a norma distribution to the data, having inputs repeat themselves would not be good. Currently I am using nested for loops but this is very inefficient especially as I start adding variables. does anybody know of a way in which I can speed up my code?
When n gets to be higher than 10 it becomes unbearably slow. I would like n to be at least 500.
t_mean = 9.74; %mm
D_mean = 324; %mm
dm_mean = 3.896; %mm
sig_u_mean = 542; %MPa
l_mean = 528; %mm
%range of values and number of random inputs
n = 100;
t = 0.01*randn(1, n) + t_mean;
D = 0.25*randn(1, n) + D_mean;
sig_u = 0.25*randn(1, n) + sig_u_mean;
dm = 0.001*randn(1, 100) + dm_mean;
l = 0.25*randn(1, 100) + l_mean;
%initialize the Pb matrix
K = zeros(1,1000);
m = 1;
tic
%loop over all possible input combinations
for i = 1 : length(t)
for j = 1 : length(D)
for k = 1 : length(sig_u)
for n = 1 : length(dm)
for o = 1 : length(l)
M = sqrt(1 + 0.31*(l_mean/sqrt(D(j)*t(i)))^2);
K(m) = ((2*t(i))/(D(j)-t(i)))*sig_u(k)*abs((1-(dm_mean/t(i)))/(1-(dm_mean/(t(i)*M))));
m = m+1;
end
end
end
end
end
toc
distributionFitter(K)
William Backhttps://es.mathworks.com/matlabcentral/profile/authors/14654826-william-backtag:es.mathworks.com,2005:Question/5593972020-07-04T12:32:20Z2020-07-04T12:32:20ZMerge specific .txt files depending on the prefix.Hello,
I have multiple .txt files with names like:
M1_mR1.txt, M1_mR2.txt,.... M1_mr100.txt
AND
M2_mr2.txt,M2_mR2.txt,..., M2_mR100.txt.
I would like to merge into one file all the files that have the prefix "M1_", and after that I would like to merge into one file all the files that have the prefix "M2_".
If I want to merge files with different suffix I am using these commads:
txtFiles = dir('mR*.txt') ; % get the text files in the present folder
N = length(txtFiles) ; % Total number of text files
iwant = cell(N,1) ; % initlaize the data required
% loop for each file
for i = 1:N
thisFile = txtFiles(i).name ;
iwant{i} = importdata(thisFile) ; % read data of the text file
end
iwant = cell2mat(iwant) ;
outFile = strcat('finalR.txt') ;
dlmwrite(outFile,iwant,'delimiter','\t')
How could I solve my problem, by modifying my code?
Ivan Michhttps://es.mathworks.com/matlabcentral/profile/authors/15708342-ivan-michtag:es.mathworks.com,2005:Question/5591272020-07-03T18:32:44Z2020-07-04T12:29:42ZFast algorithm for dynamically updating tetrahedral meshI have a tetrahedral mesh defined by the matrices X and T, where X is N-by-3 and each row represents the (x,y,z)-coordinates of a given vertex (N is the total number of vertices). Moreover, T is M-by-4 and each row represents the row indices of the 4 vertices defining a given tetrahedron. M is the total number of tetrahedrons in the mesh.
I'm trying to build a deformation solver based on a mass-spring model. At each iteration in time, spring forces on each vertex is calculated and through a numerical scheme for Newton's second law, the program calculates the new positions for the vertices that are being displaced due to said forces.
The issue is to update the mesh according to these new positions for the vertices. Triangulating the entire mesh from scratch at each iteration is prohibitively expensive, so Ideally I only want to update the vertices that are actually moving. There's also the issue of badly shaped triangles, edges being removed and added etc. I realize that dynamically updating a mesh during runtime is still an active field of research in computational geometry, however I would greatly appreciate if anyone can point me to some fast algorithms that does this, perhaps by only re-triangulating the mesh locally around the vertices that actually move. Tor Ola Solheimhttps://es.mathworks.com/matlabcentral/profile/authors/6814456-tor-ola-solheimtag:es.mathworks.com,2005:Question/5592862020-07-04T05:41:48Z2020-07-04T12:28:52ZHow to solve a non linear 3rd order differential equationHi, I need to solve a 3rd order, non linear differential equation. I would preferably like a symbolic solution for the equation, as this equation is the input for another script. The equation is as follows:
where m is a constant (for my purposes, m =1)
f is a function of variable eta, and the initial conditions are as follows:
;
;
and
I tried using the code mentioned below, but it is unable to give me a symbolic solution. Can anybody please help me solve this problem?
m = 1;
syms f(eta)
Df = diff(f,eta);
D2f = diff(f,eta,2);
ode = diff(f,eta,3)+0.5*(m+1)*f*D2f+m*(1-Df^2) == 0;
cond1 = f(0) == 0;
cond2 = Df(0) == 0;
cond3 = D2f(10^100) == 1;
conds = [cond1 cond2 cond3];
uSol(eta) = dsolve(ode,conds)Sumedh Somanhttps://es.mathworks.com/matlabcentral/profile/authors/17362344-sumedh-somantag:es.mathworks.com,2005:Question/5590762020-07-03T16:30:20Z2020-07-04T12:28:04ZHow to increas the speed of the program?I made a matrix attached herewith. The program is taking too much time for even smaller values for example c=2(fixed), g=1(fixed) and l=7. As the value of l increases the program is taking like 3-4 hours to create the matrix of order 1000. Is there any way this program can be speed up? I tried clear variable command. Thanks in advance.raina RAJhttps://es.mathworks.com/matlabcentral/profile/authors/14177104-raina-rajtag:es.mathworks.com,2005:Question/5593822020-07-04T11:41:21Z2020-07-04T12:28:01Zselection of specific value of a column from a matrixcellular=1:6
resource=[1 6;2 12;3 7;4 3;5 17]
what are the syntaxes are to use if i want cellular value select row with min column2 value 5 and more??????
output like
1 1 6
2 3 7
3 2 12
and so on...................raqib Iqbalhttps://es.mathworks.com/matlabcentral/profile/authors/18859328-raqib-iqbaltag:es.mathworks.com,2005:Question/5574612020-06-30T22:31:20Z2020-07-04T12:24:50ZIssues with audiorecorder function in Matlab online R2020a?Hi. I'm using Matlab online R2020a and I have 2 microphones and 2 speakers connected in my laptop, but when I try to use audiorecorder function I received error message: "no audio input device found on this system". Are there issues with matlab online?Eddy Armashttps://es.mathworks.com/matlabcentral/profile/authors/16180076-eddy-armastag:es.mathworks.com,2005:Question/5593282020-07-04T09:01:10Z2020-07-04T12:21:15Z4th order runge kutta for spring mass sytemWhat is wrong with the code: (Also, I am a beginner, so any suggestions for where can i learn matlab for solving odes and pdes without using ode45)
function rk()
Fo=1;m=1;wn=1;w=0.4;z=0.03;
f1=@(t,y1,y2)(y2);
f2=@(t,y1,y2)(Fo/m*sin(w*t)-2*z*wn*y2-wn*y1^2);
h=0.01;
t(1)=0;y1(1)=0;y2(1)=0;
for i=1:10000
t(i+1)=t(i)+h;
k1y1 = h*f1(t(i), y1(i), y2(i));
k1y2 = h*f2(t(i), y1(i), y2(i));
k2y1 = h*f1(t(i)+h/2,y1(i)+k1y1/2,y2(i)+k1y2/2);
k2y2 = h*f2(t(i)+h/2,y1(i)+k1y1/2,y2(i)+k1y2/2);
k3y1 = h*f1(t(i)+h/2,y1(i)+k2y1/2,y2(i)+k2y2/2);
k3y2 = h*f2(t(i)+h/2,y1(i)+k2y1/2,y2(i)+k2y2/2);
k4y1 = h*f1(t(i)+h, y1(i)+k3y1, y2(i)+k3y2);
k4y2 = h*f2(t(i)+h, y1(i)+k3y1, y2(i)+k3y2);
y1(i+1)=y1(i) + (k1y1 + 2*k2y1 + 2*k3y1 + k4y1)/6;
y2(i+1)=y2(i) + (k1y2 + 2*k2y2 + 2*k3y2 + k4y2)/6;
end
plot(t,y1)Dhrumil Patadiahttps://es.mathworks.com/matlabcentral/profile/authors/15519280-dhrumil-patadiatag:es.mathworks.com,2005:Question/5593672020-07-04T11:08:35Z2020-07-04T12:17:48ZAdd a loop and create .txt files.Hello,
I have a question about a code.
Well, my code creates by a loop multiple .txt files with specific name and format, if I use one loop in order to make my calculations. But, I would like to add one more loop in order to make my code better.
I am giving you my code here:
name=regexp(fileread('names.txt'), '\r?\n', 'split') .';
file1=regexp(fileread('data.txt'), '\r?\n', 'split') .';
.....
for n=1:numel(name);
for z=1:size(file1)
........ %making caluclations
FP=fopen(sprintf('mR%g0.txt',z),'wt');
fprintf(FP,'%s\t',file1{z},num2str(number),num2str(number);
fclose(FP);
txtFiles = dir('mR*.txt') ; % get the text files in the present folder
N = length(txtFiles) ; % Total number of text files
iwant = cell(N,1) ; % initlaize the data required
% loop for each file
for i = 1:N
thisFile = txtFiles(i).name ;
iwant{i} = importdata(thisFile) ; % read data of the text file
end
iwant = cell2mat(iwant) ;
outFile = strcat('finalR',num2str(n),'.txt') ;
dlmwrite(outFile,iwant,'delimiter','\t')
end
end
My code:
1)creates multiple mR.txt files
2)merge all multiple mR.txt files into one file, called finalR.txt
So I would like to add a for loop, which:
1) will read a file (lets call it "file2.txt") with multpile lines
2)Creates for each iteration of file2.txt mulptle files( eg M_1mR*.txt for the first iteration, M2_mR*txt for the second iteration etc)
3)Merges files M_1mR*.txt to one file , M_2mR*.txt to one file etc.
I have tried these:
for w=1:size(file1)
for z=1:size(file1)
.......
txtFiles = dir('M_*',w,'mR*.txt',z) ; % get the text files in the present folder
end
end
but it didn't work...
Could anyone help me?Ivan Michhttps://es.mathworks.com/matlabcentral/profile/authors/15708342-ivan-michtag:es.mathworks.com,2005:Question/5591332020-07-03T18:46:42Z2020-07-04T12:17:47ZRemoving Unwanted data from a bunch of dataHey there everyone
I have a set of data of an eye digram (which I attached its .mat file) and clustered it by color as shown below. However, there are some data (lines) that are disturbing and out of range that makes the diagram too much clumsy and I intend to remove them (as I indicated in the second shape with black highlighter) but I do not know how to do it. I attached the code by the way to get the main output but removing those unwanted data and make the diagram looks clean is my problem
Can anyone help me do this?
Mahdi Khalili Hezarjaribihttps://es.mathworks.com/matlabcentral/profile/authors/9641417-mahdi-khalili-hezarjaribitag:es.mathworks.com,2005:Question/5593942020-07-04T12:16:57Z2020-07-04T12:16:57ZPotential and Current TransformerCan anybody help me to perform potential and current transformer using matlab through providing the program file? It's urgent please. Rao Ehtehamhttps://es.mathworks.com/matlabcentral/profile/authors/18804737-rao-ehtehamtag:es.mathworks.com,2005:Question/5593912020-07-04T12:15:42Z2020-07-04T12:16:55ZCreating a manual timeout for bluetooth connection in MATLAB App DesignerI have created a wireless signal analyzing application using MATLAB App Designer, a HC-06 Bluetooth module, and an Arduino. The application is basically complete and I am now coding in as much error detection as possible so the app does not crash if used incorrectly.
Given the device is connected using bluetooth, there are certain instances where the application is unable to esablish a connection. If this occurs, an error is shown in the code view of the App Designer, and the app crashes. Is there any way to create a sort of timeout in the code to keep the app from crashing while in use?
Attached is a picture of the UI I've created as well as the code used to create the bluetooth connection. When the user clicks the 'Connect' button, the shown code runs to pair the bluetooth device. This is where I'd like to be able to catch a failed connection before the app crashes. Normally the error occurs at the "fopen(app.bt);" line indicating the device cannot connect.
Note: The "Message Board" area of the UI is used to display error messages to the user
% Button pushed function: ConnectButton
function ConnectButtonPushed(app, event)
% Initialization and setup of BT device
if(app.connectFlag == 0 && app.inputSelectFlag == 1 && app.wirelessSelectFlag == 1)
% Clear message board
app.MessageBoardLabelText.Text = '';
instrreset; % clear and reset any existing instrument object
app.bt = Bluetooth(app.btName,1); % create bluetooth object using user selected device
fopen(app.bt); % Open BT connection
% Lamps indicating successful connection
app.ConnectLamp.Color = [0,1,0]; % Green
app.ConnectLabel.Text = 'Connection Successful!';
app.DisconnectLamp.Color = [0.9,0.9,0.9]; % Grey
app.DisconnectLabel.Text = '';
% Update Flags
app.connectFlag = 1;
app.disconnectFlag = 0;
app.wirelessSelectFlag = 0;
% app.inputSelectFlag = 0;
% app.transmissionSelectFlag = 0;
app.signalAnalysisFlag = 0;
app.resetFlag = 0;
app.setupAxesFlag = 0;
elseif(app.connectFlag == 0 && app.inputSelectFlag == 0 && app.wirelessSelectFlag == 1)
app.MessageBoardLabelText.Text = 'Please select input device!';
app.MessageBoardLabelText.FontColor = [1.0,0.0,0.0]; % red text
elseif(app.connectFlag == 0 && app.inputSelectFlag == 1 && app.wirelessSelectFlag == 0)
app.MessageBoardLabelText.Text = 'Please select wireless device!';
app.MessageBoardLabelText.FontColor = [1.0,0.0,0.0]; % red text
elseif(app.connectFlag == 0 && app.inputSelectFlag == 0 && app.wirelessSelectFlag == 0)
app.MessageBoardLabelText.Text = 'Please select input and wireless device before connecting!';
app.MessageBoardLabelText.FontColor = [1.0,0.0,0.0]; % red text
else
app.MessageBoardLabelText.Text = 'Device is already connected!';
app.MessageBoardLabelText.FontColor = [1.0,0.0,0.0]; % red text
end
endepzolohttps://es.mathworks.com/matlabcentral/profile/authors/17433733-epzolotag:es.mathworks.com,2005:Question/5591752020-07-03T20:54:49Z2020-07-04T12:16:50Zhow to user grpstats function in this caseI have a table like (the real table is more complicated)
date month person spending
1/1/2020 January-2020 John 30
1/1/2020 January-2020 Mike 15
1/2/2020 January-2020 John 20
1/3/2020 January-2020 Kate 30
then I want to create a summary table such as
person 'count of John's spending data' 'sum of John's spending' 'average of John's spending per observation'
January-2020
February-2020
Please advise.alpedhuezhttps://es.mathworks.com/matlabcentral/profile/authors/10930090-alpedhueztag:es.mathworks.com,2005:Question/5591092020-07-03T17:47:10Z2020-07-04T12:16:01ZConverting a 3D object (in spherical coordinates) to an stl.Hello all,
I am currently working on a project in which I will eventually 3D print antenna radiation patterns. As part of the project, I have to use spherical coordinates from a 3D object and convert the file to an stl. I have explored several options for how to do this, but I was wondering if anyone had ever done this before. If so, what was your overall method to converting from the 3D object to the stl?
Thank you in advance!Erin Coxhttps://es.mathworks.com/matlabcentral/profile/authors/16015104-erin-coxtag:es.mathworks.com,2005:Question/5569032020-06-29T22:26:05Z2020-07-04T12:10:44ZRun a loop on struct fieldHi
I am running a statistical analysis. I need to run the analysis multiple times for 6 different 'sensortypes'. This data is stored in a 2x1 struct with two fields called S. The data to be inputted is in the secomd field 'ROI_Sig'. Can anyone help with getting the loop to run in the script below?
for i = 1:length(S)
ROIData = S(i).ROI_Sig;
sFiles = bst_process('CallProcess', 'process_test_permutation2', sFiles5 sFiles6, ...
'sensortypes', ROIData, ...
endDavid Loughreyhttps://es.mathworks.com/matlabcentral/profile/authors/9822557-david-loughreytag:es.mathworks.com,2005:Question/5592172020-07-03T23:38:06Z2020-07-04T12:05:57ZError checking code functionsI am having some trouble developing some error checking code for several inputs, I first use:
Testdate=input('What is the test date?(dd-mm-yyyy)','s')
Teststr=convertCharsToStrings(Testdate);
TestT=ERRORT(Testdate);
Acceldata=input('What are your accel values?( Separated by commas and from 0 deg to 270 deg)','s')
AccelD=ERRORD(Acceldata);
Tempdata=input('What are your temp values?( Separated by commas and from 0 deg to 270 deg)','s')
TempD=ERRORTemp(Tempdata);
outA=regexp(Acceldata,',','split');
outAccel=outA(1:end);
outT=regexp(Tempdata,',','split');
outTemp=outT(1:end);
Then for the first input (Testdate) I use a function displayed as:
function Testdate = ERRORT(Testdate)
if (length(Testdate)~=10) || isempty(Testdate)
Testdate=input('Input the test date in the correct format: dd-mm-yyyy.','s')
end
yearstr=Testdate(7:10);
year=str2double(yearstr);
if Testdate(7)<1 || ~ischar(year)==1 || isempty(year)==1 || (length(year)~=4) || year<0
Testdate=input('Input for the yyyy is incorrect. Try again.','s')
end
monthstr=Testdate(4:5);
month=str2double(monthstr);
if isempty(month) || ~ischar(month)==1 || month<01 || month>12 || (length(month)~=2)
Testdate=input('Input for the mm is incorrect. Try again.','s')
end
if Testdate(3)~='-' || Testdate(6)~='-'
Testdate=input('Input the test date in the correct format: dd-mm-yyyy.','s')
end
daystr=Testdate(1:2);
day=str2double(daystr);
if isempty(day) || ~isnumeric(day)==1
Testdate=input('Input for the dd is incorrect. Try again.','s')
end
if month==01 || month==03 || month==05 || month==07 || month==08 || month==10 || month==12
if day<1 || day>31
Testdate=input('Input for the dd is invalid. Try again.','s')
end
end
if month==04 || month==06 || month==09 || month==11
if day<1 || day>30
Testdate=input('Input for the dd is invalid. Try again.','s')
end
end
if month==02
if day<1 || day>29
Testdate=input('Input for the dd is invalid. Try again.','s')
end
end
This causes the inputted error message to display at the wrong time as I error check to ensure if there isn't a number for the day, month, or year, the input is left blank, or even reasonable values for the year, month, or day, or not in the presented format results in the inputted error message.
I also use another function to error check the input of Acceldata:
function Acceldata = ERRORD(Acceldata)
while isempty(Acceldata) || ischar(outAccel)==0
Acceldata=input('Must type a numerical value. Try again.')
end
This also displays the error message at the wrong time as I would like for the code to display while the Acceldata input is blank or is not a number or doesn't not have four values( as the values are supposed to be separated by commas) or the values are not separated by commas results in an input of the error message.
I also use another function to error check the input of Tempdata:
function Tempdata = ERRORTemp(Tempdata)
while isempty(Tempdata)
Tempdata=input('Must type a numerical value. Try again.')
end
if Tempdata>3 || Tempdata<2.8
Tempdata=input('Check the inputs, the values are invalid. Try again.')
end
This code displays an error for the second portion. I intend the code to display while the Tempdata input is blank or are not numbers results in the input of the error message and if the Tempdata values(separated by commas) are above 3 or below 2.8 or there aren't 4 Tempdata values or the values aren't separated by a comma results in the input of the error message.
Any suggestions or corrections that I should make?Alexandra Philiphttps://es.mathworks.com/matlabcentral/profile/authors/18685519-alexandra-philiptag:es.mathworks.com,2005:Question/5592262020-07-03T23:59:13Z2020-07-04T12:05:15ZMy code is not able to fit some data on a graphHi,
I have written a code to analyse series of dicom images from selected 3 ROIs from each image, fit their average measurements exponentially in one graph , and then plotting the results.
The code runs well for all parts except when it reachs the fit command it just does not work. I do not get any error messages, but when I run the code on that specific 'fit line', I get this command: error Fcn = iCreateError Function (nargout >4).
I really do not understand what is happening. Can someone help me please by resolving this problem?
The code is below:
xzdxbnfile_name={'E:\copied folders from CD A-H_IRONQUANTI\1818000'};
clear all
%Which image to display for selecting region
Num = 18;
dirName = pwd; %# folder path
files = dir( fullfile(dirName,'*') );
files = {files.name}'; %'# file names
files = files(3:end);
a=mat2gray(dicomread(fullfile(dirName,files{Num})));
y = [];
jj = 1;
N = 3;
figure(1);
im = imshow(a);
meanInt = [];
%%y = [];
for ii = 1:N
%%create an ROI
e = imellipse(gca,[]);
BW = createMask(e);
for k = 30:41
fname = fullfile(dirName,files{k}); %# full path to file
avoidMe = strcmp(fname,'forFilesInDir.m');
if ~avoidMe
diimg = dicomread(fname);
if ~isempty(diimg)
meanReg = diimg(BW);
meanInt(k) = mean(meanReg);
else
meanInt(k) = 0;
end
end
y(jj) = meanInt(k);
%%y = meanInt(k);
jj = jj+1;
end
end
g = y(1:12)';
h = y(13:24)';
m = y(25:36)';
x = [0.9,2,3,4.1,5.2,6.2,7.3,8.4,9.5,10.5,11.6,12]';
options = fitoptions('exp1');
options.Normalize = 'on';
options.Algorithm = ('Levenberg-Marquardt');
options.StartPoint = [209.356287641061 -0.223283499455681];
%f1 = fit(x,g,'exp1',options);
figure
f1 = fit(x,g, 'exp1', options);
hold on
f2 = fit(x,h,'exp1', options);
%plot(x,h,'b-');
hold on
f3 = fit(x,m,'exp1', options);
plot(x,g,'r', x,h,'g',x,m, 'b');Gamra Samhahttps://es.mathworks.com/matlabcentral/profile/authors/18910239-gamra-samhatag:es.mathworks.com,2005:Question/5593882020-07-04T12:02:37Z2020-07-04T12:02:37ZHow to divide a closed detected edge of an image into 8 parts from a point inside in it..?During my work course,I detcted the edge of the image. Now, I need to divide that closed edge detected image into equal parts from a point so that I can see which have greater area cointaing shaded edge portion .KRISHNA TEJA DUDEhttps://es.mathworks.com/matlabcentral/profile/authors/17812787-krishna-teja-dudetag:es.mathworks.com,2005:Question/5592322020-07-04T00:21:00Z2020-07-04T12:01:38ZHow to integrate a multiple output function using single output RK4 integrator ? % Function
function [dtheta,Stm,MM,V,G,FRK] = InverseVelocityRPS(t,th)
dtheta ;
Stm ;
MM
.
.
.
end
------
% Integrator
function qout = RK4(F,t0,h,tfinal,y0)
% ODE4 Classical Runge-Kutta ODE solver.
q = y0;
qout = q;
for t = t0 : h : tfinal-h
k1 = F(t,q);
k2 = F(t+h/2, q+h*k1/2);
k3 = F(t+h/2, q+h*k2/2);
k4 = F(t+h, q+h*k3);
q = q + h*(k1 + 2*k2 + 2*k3 + k4)/6;
qout = [qout; q]; %#ok<AGROW>
end
-----
%Integration
JointV= RK4(@InverseVelocityRPS,0,ts,1,th);
HNhttps://es.mathworks.com/matlabcentral/profile/authors/6607164-hntag:es.mathworks.com,2005:Question/5592292020-07-04T00:16:46Z2020-07-04T11:59:29ZPlotting 3D Animation from 4-D DataHi,
I'm trying to plot an animated 3D plot from some data that I've calculated. The matrix is a 4D matrix that is a function of x y z and time, where at each point, the temperature of that point is represented.
For example, in the sample values below, it can be seen that "val(:,:,1,1)" represents the temperatures at each coordinate of space in the x-y plane on the first z-plane and at the first point in time. Likewise, the values found in "val(:,:,2,1)" represent the temperatures at each coordinate of space in x-y plane for the SECOND z-plane at the first point in time. This continues until all the temperature values are displayed for each position in x, y, and z, at the first point in time. After which, the sequence repeats at "val(:,:,1,2)" which displays the temperatures at each x-y coordinate for the first z-plane but at the SECOND point in time.
val(:,:,1,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,2,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.31313 0.68158 1.1879 1.6579 1.8527 1.6579 1.1879 0.68158 0.31313 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,3,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.31313 0.68158 1.1879 1.6579 1.8527 1.6579 1.1879 0.68158 0.31313 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,4,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.31313 0.68158 1.1879 1.6579 1.8527 1.6579 1.1879 0.68158 0.31313 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,5,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.31313 0.68158 1.1879 1.6579 1.8527 1.6579 1.1879 0.68158 0.31313 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,6,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.31313 0.68158 1.1879 1.6579 1.8527 1.6579 1.1879 0.68158 0.31313 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,7,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.31313 0.68158 1.1879 1.6579 1.8527 1.6579 1.1879 0.68158 0.31313 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,8,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.31313 0.68158 1.1879 1.6579 1.8527 1.6579 1.1879 0.68158 0.31313 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,9,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.31313 0.68158 1.1879 1.6579 1.8527 1.6579 1.1879 0.68158 0.31313 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,10,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.31313 0.68158 1.1879 1.6579 1.8527 1.6579 1.1879 0.68158 0.31313 0
0 0.2802 0.6099 1.063 1.4835 1.6579 1.4835 1.063 0.6099 0.2802 0
0 0.20078 0.43701 0.76167 1.063 1.1879 1.063 0.76167 0.43701 0.20078 0
0 0.1152 0.25074 0.43701 0.6099 0.68158 0.6099 0.43701 0.25074 0.1152 0
0 0.052924 0.1152 0.20078 0.2802 0.31313 0.2802 0.20078 0.1152 0.052924 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,11,1) =
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
val(:,:,1,2) =
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0Adalric Leunghttps://es.mathworks.com/matlabcentral/profile/authors/8698927-adalric-leungtag:es.mathworks.com,2005:Question/5592562020-07-04T04:07:31Z2020-07-04T11:56:41Zfixed bed adsorption column model-solving PDE-freundlish isothermfunction main
%System Set-up %
%Define Variables
%D = 3*10^-8; % Axial Dispersion coefficient
%v = 1*10^-3; % Superficial velocity
%epsilon = 0.4; % Voidage fraction
%k = 3*10^-5; % Mass Transfer Coefficient
%Kf=2.5*10^-5; %freundlish parameter
%nf= 1.45; %freundlish constant
cFeed = 10; % Feed concentration
L = 1; % Column length
t0 = 0; % Initial Time
%tf = 1000; % Final time
tf = 2000; % Final time
dt = 0.5; % Time step
% z=[0:0.01:L]; %Mesh generation
z = [0:0.0005:L]; %Mesh generation
t = [t0:dt:tf];% Time vector
n = numel(z); % Size of mesh grid
%Initial Conditions / Vector Creation
c0 = zeros(n,1);
c0(1) = cFeed;
q0 = zeros(n,1); % t = 0, q = 0 for all z, this makes sense to me
y0 = [c0 ; q0]; % Appends conditions together
%ODE15S Solver
[T, Y] = ode15s(@(t,y) MyFun(t,y,z,n),t,y0);
%plot(T,Y);
plot(T,Y(:,n)/cFeed)
end
function DyDt=MyFun(~, y, z, n)
% Defining Constants
D = 3*10^-8; % Axial Dispersion coefficient
v = 1*10^-3; % Superficial velocity
epsilon = 0.4; % Voidage fraction
k = 3*10^-5; % Mass Transfer Coefficient
Kf=2.5*10^-5; %freundlish parameter
nf= 1.45; %freundlish constant
% Variables being allocated zero vectors
c = zeros(n,1);
q = zeros(n,1);
DcDt = zeros(n,1);
DqDt = zeros(n,1);
DyDt = zeros(2*n,1);
zhalf = zeros(n-1,1);
DcDz = zeros(n,1);
D2cDz2 = zeros(n,1);
c = y(1:n);
q = y(n+1:2*n);
% Interior mesh points
zhalf(1:n-1)=(z(1:n-1)+z(2:n))/2;
for i=2:n-1
%DcDz(i) = ((z(i)-z(i-1))/(z(i+1)-z(i))*(c(i+1)-c(i))+(z(i+1)-z(i))/(z(i)-z(i-1))*(c(i)-c(i-1)))/(z(i+1)-z(i-1));
DcDz(i) = (c(i)-c(i-1))/(z(i)-z(i-1));
D2cDz2(i) = (zhalf(i)*(c(i+1)-c(i))/(z(i+1)-z(i))-zhalf(i-1)*(c(i)-c(i-1))/(z(i)-z(i-1)))/(zhalf(i)-zhalf(i-1));
end
% Calculate DcDz and D2cDz2 at z=L for boundary condition dc/dz = 0
DcDz(n) = 0;
D2cDz2(n) = -1.0/(z(n)-zhalf(n-1))*(c(n)-c(n-1))/(z(n)-z(n-1));
% Set time derivatives at z=0
% DcDt = 0 since c=cFeed remains constant over time and is already set as initial condition
% Standard setting for q
DqDt(1) = k*(kf*(c(1)^(1/nf))-q(1));
DcDt(1) = 0.0;
% Set time derivatives in remaining points
for i=2:n
%Equation: dq/dt = K(q*-q) where q*=kf*(c^(1/nf))
DqDt(i) = k*(kf*(c(i)^(1/nf))-q(i));
%Equation: dc/dt = D * d2c/dz2 - v*dc/dz - ((1-e)/(e))*dq/dt
DcDt(i) = D*D2cDz2(i) - v*DcDz(i) - ((1-epsilon)/(epsilon))*DqDt(i);
end
% Concatenate vector of time derivatives
DyDt = [DcDt;DqDt];
end
This is the code which I am using. I don't have much knowledge about Matlab but I need to finish the code for my thesis. My question is, I need to model a fixed bed to obtain the breakthrough curves using freundlish isotherm, so, I would like to know how to obtain these curves (C/C0 vs t) from this code. i cant run this code i dont know where is the problem. I would appreciate any help. Thank you very much nashwa tarekhttps://es.mathworks.com/matlabcentral/profile/authors/18668615-nashwa-tarektag:es.mathworks.com,2005:Question/5105062020-03-12T10:47:12Z2020-07-04T11:52:31ZFinding distance between two curves at diffrent points1.Suppose the curves are defined, how do i find the distance between two curves at diffrent points.
Curve 1= f(x)
curve 2 = g(x)
Do i need to define points on one of the curve to find out the required distance???
For exmple I am posting an image.
Important note-
I need distance at diffrent points between two curves and not single point nor am I looking for minimum distance between curves.
Perpendicular distance from tangent as shown in image.Praveen Patnaikhttps://es.mathworks.com/matlabcentral/profile/authors/17640651-praveen-patnaiktag:es.mathworks.com,2005:Question/5593192020-07-04T08:21:20Z2020-07-04T11:52:31Zow to save image from exes to database I have generate a GUI to detect brain tumor . I want to save that image and patiet name in data base . kindly give me the solutionrabia ahmadhttps://es.mathworks.com/matlabcentral/profile/authors/15485381-rabia-ahmadtag:es.mathworks.com,2005:Question/5575992020-07-01T07:59:09Z2020-07-04T11:42:45ZAdding two linear inequality constraints in Optimization toolbox I have the following code for maximizing revenue for a plant:
function varargout = EbsOptimize5_3(para)
para = reshape(para, 2, []);
% para = [x11,x12,x13;x21,x22,x23];
%para = reshape(para, 2, []);
global asmInfo app oc model objects Sun SunDNI SunDNImeasm M1 M2 M1measm M2measm TotalmassFlow;
if (~(size(asmInfo)))
disp('call EbsOpen.dll')
asmInfo = NET.addAssembly('C:\Program Files\Ebsilon\EBSILONProfessional 14 P3\EbsOpen.dll');
app = EbsOpen.ApplicationClass;
oc = app.ObjectCaster;
model = app.Open('C:\Users\Hassan Bukhari\Desktop\Priority Study\New EXP CSP 3_with_TimeSeries.ebs');
model.ActivateProfile('Charging');
objects = model.Objects;
%%%%%%%%%%%%
Sun = oc.CastToComp117(objects.Item('Sun'));
SunDNI = Sun.DNI;
%SunDNImeasm = Sun.DNI.Value;
M1 = oc.CastToComp33(objects.Item('Start_value_4'));
M2 = oc.CastToComp33(objects.Item('Start_value_5'));
M1measm = M1.M;
M2measm = M2.M;
end
SunDNImeasm = [600; 700];
powerPrice = [100; 150];
Power = zeros(1,length(SunDNImeasm));
Revenue = zeros(1,length(SunDNImeasm));
M1v = zeros(1,length(SunDNImeasm));
M2v = zeros(1,length(SunDNImeasm));
massFlow = zeros(1,length(SunDNImeasm));
for i=1:length(SunDNImeasm)
Sun.DNI.Value = SunDNImeasm(i);
M1measm.Value = para(1,i);
M2measm.Value = para(2,i);
errors = app.NewCalculationErrors();
model.Simulate(errors);
Gen = oc.CastToComp11(objects.Item('Generator'));
%Power = (Gen.QREAL.Value);
Power(i) = Gen.QREAL.Value/1000 ;
M1v(i) = M1measm.Value;
M2v(i) = M2measm.Value;
massFlow(i) = 3600*(M1v(i)+M2v(i));
Revenue(i) = -(Power(i)*powerPrice(i));
end
TotalRevenue = sum(Revenue);
TotalmassFlow = sum(massFlow);
varargout{1} = TotalRevenue;
if nargout > 1
varargout{2} = Power;
varargout{3} = Revenue;
varargout{4} = TotalmassFlow;
varargout{5} = M1v;
varargout{6} = M2v;
end
%TotalPower = sum(Power);
%TotalRevenue = Power*powerPrice;
%TotalRevenue = sum(Revenue);% Aineq=-ones(1,nvars);
% bineq=-9.36e3/3600;
end
I have added a linear inquality constraint on total mass flow as:
If I want to add another constraint on "Power" being calculated by the black box model attached to MATLAB, how can I do that?
Hussain Jahttps://es.mathworks.com/matlabcentral/profile/authors/4971894-hussain-jatag:es.mathworks.com,2005:Question/5546472020-06-25T14:38:39Z2020-07-04T11:41:51ZDisplaying properties defined in MATLAB application How can properties defined in an application be displayed ? The properties have numerical values. I have tried using spinners and EditText Fields but there is an error in the data type. Aditya Bhatthttps://es.mathworks.com/matlabcentral/profile/authors/9708710-aditya-bhatttag:es.mathworks.com,2005:Question/4078172018-06-28T08:26:53Z2020-07-04T11:36:29ZIs there a way to stop compiling process when the model has started to compile in Simulink? I am running Simulink with Raspberry Pi and when I had hit RUN button, I realized that the model had some errors, but couldn't find any option to TERMINATE THE COMPILATION PROCESS
Either I'd have to wait 20 minutes for the compilation process to complete or restart MATLAB.
I had to chose the 2nd one. Anuj Patilhttps://es.mathworks.com/matlabcentral/profile/authors/10260332-anuj-patiltag:es.mathworks.com,2005:Question/5593792020-07-04T11:33:55Z2020-07-04T11:33:55ZHow to plot images with different sizes in one figure?I have 5 images and I would like to plot them like:
fig1 fig2
fig3 fig4 fig5
i.e. I would like to have two rows, the first row does something like;
subplot(1,2,1)
imshow(fig1)
subplot(1,2,2)
imshow(fig2)
and the second row:
subplot(1,3,1)
imshow(fig3)
subplot(1,3,2)
imshow(fig4)
subplot(1,3,3)
imshow(fig5)
If I use span, the first row is not centered. If I use subplot I could only have 2x3 grid, are there anyway to achieve this ?
xingze tianhttps://es.mathworks.com/matlabcentral/profile/authors/11012585-xingze-tiantag:es.mathworks.com,2005:Question/5593402020-07-04T09:56:52Z2020-07-04T11:33:02ZHow to move the scroll bar in TextArea using codes?( MATLAB App Designer)I wanna create a text area with changing text while the app is running. However, the position of the scroll bar keeps unchanged during the running process which makes the renewed information cannot be seen(if the text area is not large enough). I'm wondering if I can use some codes to control the movement of the scroll bar and keeps it at the lower position? Thanks a lot!minghong jianghttps://es.mathworks.com/matlabcentral/profile/authors/13934822-minghong-jiangtag:es.mathworks.com,2005:Question/5593762020-07-04T11:32:58Z2020-07-04T11:32:58ZHow to fit with case differentiation I guess this is a really tricky question and might solved with a good amount of mathmatical knowledge. But first things first:
I want to execute a fit with a custom equation in cftool. The problem remains in the fact that the function consist of case differentation:
atan((2*d*w)/(v^2-w^2)) for w < v
π/2 for w = v
π/2 + atan((2*d*w)/(v^2-w^2)) for w > v
with w being 'x'
Actually I got handed the solution: fitting with :
acos((v^2 - w^2)/sqrt((2*d*w)^2 + (v^2 - w^2)^2)).
But how you hade have approached that problem?Niklas Kurzhttps://es.mathworks.com/matlabcentral/profile/authors/18516014-niklas-kurztag:es.mathworks.com,2005:Question/5593702020-07-04T11:11:27Z2020-07-04T11:31:08ZHo to modify Fixed-Point Matlab Function?Hello,
I have converted a Matlab Function block using the Fixed-Point Tool.
I now want to modify the behavior of the function but I cannot as the converted function is blocked on the Fixed-Point one.
How can I unblock it to be able to apply the changes?Matteo Manzinihttps://es.mathworks.com/matlabcentral/profile/authors/12014297-matteo-manzinitag:es.mathworks.com,2005:Question/5585382020-07-02T15:56:37Z2020-07-04T11:29:51ZCustering data by colorHey there everyone.
I have a series of data (50000 x 2 matrix) of an eye diagram and when I plot them. It has a solid blue output.
What I have in mind is to cluster this data by color in terms of their density (the more the density, the more color tends from blue to red) as in the second figure I sent (contauning blues, greens and tinges of red and yellow in the center). How can I accomplish this in matlab?
Thank you
Mahdi Khalili Hezarjaribihttps://es.mathworks.com/matlabcentral/profile/authors/9641417-mahdi-khalili-hezarjaribitag:es.mathworks.com,2005:Question/5592682020-07-04T04:41:12Z2020-07-04T11:27:19Z3D-Surface between 2 lines.Hi all,
Previously with one of the Mathwork community users' (darova) suggestion we created 3D surfaces on the sphere.
Please find the script below.
Here I have 3 surfaces the one of which (green) is below the other 2 surfaces.
Now, I aim to fill the gap between the top (red) and bottom (green) surfaces by creating an additional surface (i.e. an oblique surface (a slightly tilted surface)).
To make it clearer, in the output image of the attached code one can see 2 lines between the top (red) and bottom (green) surfaces.
I aim to create a surface between those 2 lines in order to close the gap.
I've tried several ways, and also a triangulation method, however, was not successfull.
Could you please make a suggestion on this.
I appreciate the time you spend.
Regards
l1 = [-3.53 -3.16 -3.543 -3.359];
l2 = [-3.16 -3.16 -3.359 -2.807];
l3 = [-3.16 -3.846 -2.807 -2.518];
l4 = [-3.846 -3.925 -2.518 -3.254];
l5 = [-3.925 -3.53 -3.254 -3.543];
ll1 = [-4.05 -4.690 -3.274 -3.395];
ll2 = [-4.690 -4.479 -3.395 -2.728];
ll3 = [-4.479 -4.347 -2.728 -2.597];
ll4 = [-4.347 -3.978 -2.597 -2.545];
ll5 = [-3.978 -4.05 -2.545 -3.274];
c1 = [-4.03 -3.966 -3.229 -2.532];
c2 = [-3.966 -3.872 -2.532 -2.545];
c3 = [-3.872 -3.932 -2.545 -3.229];
c4 = [-3.932 -4.03 -3.229 -3.229];
xl1 = [l1(1) l1(2) l2(2) l3(2) l4(2) l1(1)];
yl1 = [l1(3) l1(4) l2(4) l3(4) l4(4) l1(3)];
xl2 = [ll1(1) ll1(2) ll2(2) ll3(2) ll4(2) ll1(1)];
yl2 = [ll1(3) ll1(4) ll2(4) ll3(4) ll4(4) ll1(3)];
xf = [c1(1) c1(2) c2(2) c3(2)];
yf = [c1(3) c1(4) c2(4) c3(4)];
rf = 6.8;
gd1 = [2;length(xl1);xl1(:);yl1(:)];
dl1 = decsg(gd1);
[p1,e1,t1] = initmesh(dl1,'hmax',0.2);
z1 = sqrt(49 - p1(1,:).^2 - p1(2,:).^2);
ff1.vertices = [p1' z1(:)];
ff1.faces = t1(1:3,:)';
gd2 = [2;length(xl2);xl2(:);yl2(:)];
dl2 = decsg(gd2);
[p2,e2,t2] = initmesh(dl2,'hmax',0.2);
z2 = sqrt(49 - p2(1,:).^2 - p2(2,:).^2);
ff2.vertices = [p2' z2(:)];
ff2.faces = t2(1:3,:)';
gdf = [3;4;xf(:);yf(:)];
dlf = decsg(gdf);
[pf,ef,tf] = initmesh(dlf,'hmax',0.2);
zf = sqrt(47.5 - pf(1,:).^2 - pf(2,:).^2);
ff3.vertices = [pf' zf(:)];
ff3.faces = tf(1:3,:)';
[x,y,z] = sphere(20);
surf(7*x,7*y,7*z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xl1,yl1,'linew',2)
h1 = patch(ff1,'facecolor','b');
hold on
%[x,y,z] = sphere(20);
surf(7*x,7*y,7*z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xl2,yl2,'linew',2)
h2 = patch(ff2,'facecolor','r');
hold on
%[x,y,z] = sphere(20);
surf(7*x,7*y,7*z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xf,yf,'linew',2)
hf = patch(ff3,'facecolor','g');
xfl = [-4.0300 -4.0500 -3.966 -3.978];
yfl = [-3.2290 -3.2740 -2.532 -2.545];
zfl = [zf(1) z2(5) zf(2), z2(4)];
hline1=plot3(([xfl(1) xfl(2)]),([yfl(1) yfl(2)]),([zfl(1) zfl(2)]),'k');
hline2=plot3(([xfl(3) xfl(4)]),([yfl(3) yfl(4)]),([zfl(3) zfl(4)]),'k');
hold on
set(hline1,'linewidth',2)
set(hline2,'linewidth',2)
Mammadbaghir Baghirzadehttps://es.mathworks.com/matlabcentral/profile/authors/16688975-mammadbaghir-baghirzadetag:es.mathworks.com,2005:Question/4671172019-06-14T14:59:34Z2020-07-04T11:24:21Zif-statement with conditions.Write a function called picker that takes three input arguments called condition, in1 and in2 in this order. The argument condition is a logical. If it is true, the function assigns the value of in1 to the output argument out, otherwise, it assigns the value of in2 to out.
This is a problem from a course that I am taking on Coursera. I get a correct output for "true" but the output for the "false" condition is always wrong. Please, any kind of help will highly appreciated.
Here is my code:
function out = picker(condition,in1,in2)
if true
out = in1;
else
out = in2;
end
endKETAN PATELhttps://es.mathworks.com/matlabcentral/profile/authors/6858178-ketan-patel