https://uk.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-06-24T03:14:51Ztag:uk.mathworks.com,2005:Question/8628552021-06-22T23:54:18Z2021-06-24T03:14:51Zchirp with carrier frequency using LinearFMWaveformHello,
Regarding the object phased.LinearFMWaveform, if wished to design a chirp with a specific carrier frequency, would that be equivalent to the specifying the property 'frequency offset'?
Thanks in advance.
KatiaKatiahttps://uk.mathworks.com/matlabcentral/profile/authors/1921416tag:uk.mathworks.com,2005:Question/8611402021-06-21T04:55:08Z2021-06-24T03:11:24ZFind the meaning of each line of code clearvars
clc
syms y(t) s Y Dy(t)
C = input('Enter the coeff. of D2y, Dy and y as an array: ');
F = input('Enter the non-homogeneous part f(t): ');
IC = input('Enter the initial conditions [y0 Dy0]: ');
DEq = C(1)*diff(y,2)+C(2)*diff(y,1)+C(3)*y -F;
LDEq = laplace(DEq);
LDEq1 = subs(LDEq,{laplace(y(t),t,s),y(0),subs(diff(y(t), t), t, 0)},{Y, IC(1),IC(2)});
Ys = solve(LDEq1,Y);
y = collect(simplify(ilaplace(Ys)));
disp('The solution of the given DE is: ');
disp(char(y))
fplot(y)
title('Plot of the Solution')surendra agrawalhttps://uk.mathworks.com/matlabcentral/profile/authors/19809179tag:uk.mathworks.com,2005:Question/8638102021-06-24T01:32:22Z2021-06-24T03:08:54Zhow to generate cell array based on the size of it.My command is B = arrayfun(@(N) randi(2,1,N), repelem((1:3).',5), 'uniform', 0)
when i run it generates B= 15×1 cell array
{[ 2]}
{[ 1]}
{[ 3]}
{[ 3]}
{[ 2]}
{1×2 double}
{1×2 double}
{1×2 double}
{1×2 double}
{1×2 double}
{1×3 double}
{1×3 double}
{1×3 double}
{1×3 double}
{1×3 double}
but the values inside the array are
1
1
2
1
2
[2,1]
[2,1]
[1,2]
[2,2]
[1,1]
[2,2,1]
[1,2,1]
[2,2,2]
[1,1,1]
[2,1,2]
Actually i need to get
1
1
3
1
1
for first 5 rows the value should be 1 as it is 1x1 double
[1,2]
[2,1]
[3,2]
[3,2]
[2,1]
for the next 5 rows the values should be 1,2 and not more than 2, and should not have 2 by leaving 1
[1,2,1]
[3,1,3]
[2,3,3]
[1,2,2]
[3,3,1]
for the next 5 rows the values should not have 3 by leaving 2 and should not have 2 by leaving 1.
Could anyone please help me with this.
jaah navihttps://uk.mathworks.com/matlabcentral/profile/authors/11695462tag:uk.mathworks.com,2005:Question/8630452021-06-23T06:39:57Z2021-06-24T03:06:41ZHello, I'm a student and I look for a solution for Matlab. I'm quite beginner to use Matlab. Could you pls help me to write it through Matlab? I need how to write these codes JALALUDIN ARIShttps://uk.mathworks.com/matlabcentral/profile/authors/22889241tag:uk.mathworks.com,2005:Question/8638402021-06-24T02:17:01Z2021-06-24T03:04:55ZCreate a row vector Create a row vector named x that starts at 1, ends at 10, and contains 5 elements.Francis Adams Kwofiehttps://uk.mathworks.com/matlabcentral/profile/authors/22895856tag:uk.mathworks.com,2005:Question/8638052021-06-24T01:29:42Z2021-06-24T03:03:45ZExtract the center blob of an imageI'm new to the matlab and I was able to label the white dots but i want to extract the center of one of these dots usually the dot on the center regardless the size of the image itself and ignore that around borders; How can I approach this.
I= imread('dots18.jpg');
I = im2bw(I);
imshow(I);
[lab,num]=bwlabel(I);
I attached two image one original and the other what I want to do.zeya Ahttps://uk.mathworks.com/matlabcentral/profile/authors/6199341tag:uk.mathworks.com,2005:Question/8638602021-06-24T02:57:41Z2021-06-24T02:57:41ZHow can I generate three random matrices from 20 percent of the rows of a 2000 by 80 matrix, using for loop?Let's X=[2000 by 80]. Now I want to get X1, X2 and X3 randomly from X. Each matrix is 20 percent of the X.
Please help me out.
Thank youKhanhttps://uk.mathworks.com/matlabcentral/profile/authors/21229238tag:uk.mathworks.com,2005:Question/8638452021-06-24T02:20:32Z2021-06-24T02:55:49ZMatlab plot command functionPlot out the function y(t) = A cos(xt + s(t)), where A
= 1, x = 2 and s(t) = -2sin(t) over 0 to 40 sec in increments of 0.05 sec. verStudenthttps://uk.mathworks.com/matlabcentral/profile/authors/22903246tag:uk.mathworks.com,2005:Question/8638552021-06-24T02:53:33Z2021-06-24T02:53:33ZHow do I solve this equation in MatLab?Find the area of the region bounded by the hyperbola 9x^2−4y^2=36 and the line x=3.
I cannot find out the proper way to input this into MatLab. It requires trig substitution so I believe the problem stems from there but I am new to MatLab and don't know what I can do to fix it.
Here is my code:
>> syms x
>> EQ = 3*sqrt(x^2-4)
EQ =
3*(x^2 - 4)^(1/2)
>> A = int(EQ,2,3)
A =
log(161 - 72*5^(1/2)) + (9*5^(1/2))/2
>>
Here is the actual answer to the problem:
(9/2)*sqrt(5) - 6*ln((3 + sqrt(5))/2)Isaac Hewitthttps://uk.mathworks.com/matlabcentral/profile/authors/22713756tag:uk.mathworks.com,2005:Question/8620202021-06-22T04:13:37Z2021-06-24T02:51:40ZParallel processing remote and server logs collection / scpI would like to stream a file using HTTP endpoint / scp so that I can collect the logs from a remote server.
Is there a way ,parallel.internal.logging.enableClientLogging or parallel can help me connecting the input and output model. I have model where I use ugetdir to collect logs and then process the logs.
But now I have larger system where logs should be downloaded and processed.
I accept a HTTP POST request which will contain the following JSON in its body:
{
event,
entity,
actor,
machines,
tests,
options
}
I'II call back the HTTP domain name mentioned in the actor, so that it will give back the JSON of all the log files generated for that job
Can you please suggest me how (
JobStorageLocation
) can do this ?
Thank you!Joggerhttps://uk.mathworks.com/matlabcentral/profile/authors/7949204tag:uk.mathworks.com,2005:Question/8609052021-06-20T17:53:07Z2021-06-24T02:47:12Zhow can i plot R2(regression line) between target and prediction Please explain how can i plot R2 as regression line between target and prediction in matlab
Can some one please share the code ?
i am attaching a sample graph.NNhttps://uk.mathworks.com/matlabcentral/profile/authors/15064601tag:uk.mathworks.com,2005:Question/4524132019-03-26T09:29:58Z2021-06-24T02:37:46ZSimulink- error in hydraulic simulationHi all,
I have the following error when running the simulation:
``An error occurred while running the simulation and the simulation was terminated
Caused by:
At time 10.819689, an assertion is triggered. Pressure at port A is less than the minimum valid pressure. The assertion comes from:
Block path: TMS_passive/Cold water return line1
Assert location: between line: 144, column: 16 and line: 144, column: 19 in file: C:\Program Files\MATLAB\R2016a\toolbox\physmod\simscape\library\m\+foundation\+thermal_liquid\two_port_dynamic.ssc ``
This happen when external temperature is below to a certain value. I cannot find root cause of the problem.
Thank you
ivan caravitahttps://uk.mathworks.com/matlabcentral/profile/authors/5068127tag:uk.mathworks.com,2005:Question/8501902021-06-07T18:29:45Z2021-06-24T02:26:57ZAdd listener() or a callback function to app designer?I want to sense something continuously in my GUI (along with other functionalities of the GUI like all other buttons have different functionalities). I was wondering how to add a listener to my GUI. I would be using a read function to read a bit state of my microcontroller. However, the app designer architecture is not allowing me to edit all the part of the code and hence I am not sure how to proceed with making a function which can continuously sense() one input and then if any other button is pressed then the GUI should enter into the button_callback() function di the job and get back to the sense() function. In other words, I want all the other stuff of my GUI to be as an interrupt and one of the main parts of the code should be the sense() function.
Please let me know your inputs.
Thanks, in advance!Jay Vaidyahttps://uk.mathworks.com/matlabcentral/profile/authors/16218757tag:uk.mathworks.com,2005:Question/8638502021-06-24T02:23:58Z2021-06-24T02:23:58Zgraph wont display on a simple codehelo everyone, im not good at using Matlab. Hence, i need help on my coding. It is a simple code that just loops and adds the value of m for every loop and n is used as a counter. But why wont it display the graph? im planning on making the graph with m as the x axis and P as the y axis. Thank you so much everyone. Here is the coding:
m=input("input mass");
n=0;
while n<10
P=12.34321*m;
plot(m,P)
grid
pause(0.0001)
disp(m)
disp(P)
m=m+50;
n=n+1;
endWan Muhammad Haikal Bin Wan Mohd Nadzrihttps://uk.mathworks.com/matlabcentral/profile/authors/21413833tag:uk.mathworks.com,2005:Question/8637352021-06-23T21:31:56Z2021-06-24T02:21:48ZCreate a Loop for this processI have a process which works fine. You can see the code below. I need to create a loop for the process. I need the loop to take in multiple number of c. c is usually a 3 by 3 matrix. L is usual a 1 by 12 matrix.
n=3;
c1=[12 40 13;10 11 70;80 9 1]; % C matrix for member 1
c2=[0 0 -1;0 1 0;1 0 0]; % C matrix for member 2
c3=[0 1 0;0 0 1;1 0 0]; % C matrix for member 3
L1=[13 14 15 16 17 18 1 2 3 4 5 6]; % for member 1
L2=[1 2 3 4 5 6 7 8 9 10 11 12]; % for member 2
L3=[19 20 21 22 23 24 7 8 9 10 11 12]; % for member 3
L=[L1;L2;L3];
T1=zeros(size(L1,1));
T2=zeros(size(L2,1));
T3=zeros(size(L3,1));
for i=1:n
for j=1:n
T1(i,j)=c1(i,j);
T1(i+3,j+3)=c1(i,j);
T1(i+6,j+6)=c1(i,j);
T1(i+9,j+9)=c1(i,j);
T2(i,j)=c2(i,j);
T2(i+3,j+3)=c2(i,j);
T2(i+6,j+6)=c2(i,j);
T2(i+9,j+9)=c2(i,j);
T3(i,j)=c3(i,j);
T3(i+3,j+3)=c3(i,j);
T3(i+6,j+6)=c3(i,j);
T3(i+9,j+9)=c3(i,j);
end
endDARLINGTON ETAJEhttps://uk.mathworks.com/matlabcentral/profile/authors/8753940tag:uk.mathworks.com,2005:Question/8638252021-06-24T02:02:30Z2021-06-24T02:19:33ZPrint Out Txt File Column DataHi, i wanna ask...
Im just learn about how to read a txt file and write some column data from it into another txt files. So i have these datas in my original txt file :
2019 05 03 00 00 59 39296.64 154.74 -9052.05 39296.94 0.003938 -0.226401 40326.04
2019 05 03 00 01 59 39296.68 155.35 -9052.87 39296.98 0.003953 -0.226420 40326.26
2019 05 03 00 02 59 39296.95 155.96 -9053.74 39297.26 0.003969 -0.226440 40326.73
2019 05 03 00 03 59 39297.37 155.82 -9054.47 39297.68 0.003965 -0.226455 40327.30
2019 05 03 00 04 59 39297.34 154.31 -9053.50 39297.64 0.003927 -0.226432 40327.04
2019 05 03 00 05 59 39296.21 151.67 -9050.10 39296.50 0.003859 -0.226356 40325.17
2019 05 03 00 06 59 39296.17 150.15 -9049.32 39296.46 0.003821 -0.226338 40324.95
The data above are without header. And, i want to write it again BUT i just need the data in 3rd, 4th, 5th (time data in hour, minute, and second), and 10th (magnetic data in nano tesla) column (from left) and write the data in another txt file.
In Matlab Guide (GUI), i have just write these codes :
formku = guidata(gcbo);
[namafile1,direktori]=uigetfile('*.txt','Load Magnet Data LEMI');
eval(['cd ''' direktori ''';']);
eval(['dataku=load(''' namafile1 ''')']);
[namafile2, direktori] = uiputfile('*.txt', 'save as')
eval(['cd ''' direktori ''';']);
namafile2=[namafile2]
fout=fopen(namafile2,'w');
tahun = dataku(:,1); %: Mendapatkan data tahun pada kolom 1
bulan = dataku(:,2); %: Mendapatkan data bulan pada kolom 2
tanggal = dataku(:,3); %: Mendapatkan data tanggal pada kolom 3
jam = dataku(:,4); %: Mendapatkan data jam pada kolom 4
menit = dataku(:,5); %: Mendapatkan data menit pada kolom 4
detik = dataku(:,6); %: Mendapatkan data detik pada kolom 6
xmagnet = dataku(:,7); %: Mendapatkan data magnet arah sumbu x pada kolom 7
ymagnet = dataku(:,8); %: Mendapatkan data magnet arah sumbu y pada kolom 8
zmagnet = dataku(:,9); %: Mendapatkan data magnet arah sumbu z pada kolom 9
h = dataku(:,10); %: Mendapatkan data medan magnet Komponen H pada kolom 10
w = (3600*jam)+(60*menit)+ detik;
kolom = [jam; menit; detik];
xi =[min(w):1:max(w)];
fprintf(fout,'%8s %8s\n','Waktu','Komponen H Magnet');
for i=1:length(h)
fprintf(fout,'%d %.2f\n ', kolom, h);
end;
fclose(fout);
The above code i write is doesnt work well by using 2 or more column (im sucessful if it just 1 column, ex : h = dataku(:,10) in column 10), because i want to put the 3rd, 4th, and 5th column right before the 10th column so that the 3rd column become 1st column, 4th column become 2nd column, 5th column become 3rd column, and 10th column become 4th column in my new txt files (re-write).
So in this case, i just want to open an original txt file (attached) contained with those datas and then re-write the data inside but only with a specific column i want to choose.... Please help me out.... Thank you very much...Tyann Hardynhttps://uk.mathworks.com/matlabcentral/profile/authors/19686611tag:uk.mathworks.com,2005:Question/4807962019-09-17T15:16:16Z2021-06-24T02:15:01ZNot responding on startup, macOS MojaveI have just installed MATLAB 2019b on a Macbook Pro 2019 running macOS Mojave 10.14.6.
Just after installation, Matlab ran fine. However, if I now try to open it I see the splash screen then it freezes on the Matlab window showing no content and I have to force quit. If I run from the command line with -nodesktop it works and I can even load the desktop from there and it works ok. But if I try to load directly it hangs. I doubt it is a conflict as I have installed barely anything else on this macbook yet.William Smithhttps://uk.mathworks.com/matlabcentral/profile/authors/3990217tag:uk.mathworks.com,2005:Question/8635802021-06-23T17:48:52Z2021-06-24T02:10:49Zcould anyone help me to solve the issue in the following commandwhen i run the command
B = arrayfun(@(N) randi(2,N), repelem((1:3).',5), 'uniform', 0)
i am getting B = 15×1 cell array
{[ 1]}
{[ 1]}
{[ 1]}
{[ 2]}
{[ 2]}
{2×2 double}
{2×2 double}
{2×2 double}
{2×2 double}
{2×2 double}
{3×3 double}
{3×3 double}
{3×3 double}
{3×3 double}
{3×3 double} and the data inside are
3
2
2
2
2
[1,1;1,1]
[1,1;2,1]
[1,3;3,1]
[3,1;1,3]
[1,1;1,1]
[1,1,3;1,2,2;1,2,1]
[3,2,2;3,1,3;1,2,3]
[1,2,2;1,3,1;1,2,3]
[3,1,1;3,3,1;3,2,3]
[3,2,1;3,1,1;3,2,1]
but I actually need B =
15×1 cell array
{1×1double}
{1×1 double}
{1×1 double}
{1×1 double}
{1×1 double}
{1×2 double}
{1×2 double}
{1×2 double}
{1×2 double}
{1×2 double}
{1×3 double}
{1×3 double}
{1×3 double}
{1×3 double}
{1×3 double} containing the following values
3
2
2
2
2
[1,1]
[1,1]
[1,3]
[3,1]
[1,1]
[1,1,3]
[3,2,2]
[1,2,2]
[3,1,1]
[3,2,1]
could anyone please help me to get it.jaah navihttps://uk.mathworks.com/matlabcentral/profile/authors/11695462tag:uk.mathworks.com,2005:Question/8638352021-06-24T02:07:55Z2021-06-24T02:07:55ZIs it possible to easily disable default interactivity for all axes?Previous staff-provided answers indicated that the code snippet
set(groot, 'defaultAxesCreateFcn', @(ax,~) disableDefaultInteractivity(ax))
in startup.m would disable the default interactivity for all axes. This seems simple and practical. However, when using more recent versions of Matlab (e.g. R2020a) this no longer seems to work - the default interactivity will still be active in all figures, even if the axes creation function is adjusted as shown above. The code described here apparently works, but seems like a far more complicated way to achieve the same result. Is there a simpler / more direct way to do this in more recent versions of Matlab?G. Sparkshttps://uk.mathworks.com/matlabcentral/profile/authors/7850894tag:uk.mathworks.com,2005:Question/8638302021-06-24T02:05:36Z2021-06-24T02:05:36Zhow to import the C code generated by simulink into ccs?
Please tell me how to import the C code generated by simulink into ccs? I am importing the folder directly, and the files in the folder are not visible. Thank you!chaozhen wanghttps://uk.mathworks.com/matlabcentral/profile/authors/22329952tag:uk.mathworks.com,2005:Question/2647622016-01-22T08:23:45Z2021-06-24T02:04:31ZHow to multiply function handles?Hello,
I would like to calculate and to plot the following equation:
f(t,x) = (beta_hat*s(t,x)*[I(t,x)]^(beta_hat-1))*exp(-[I(t,x)]^beta_hat)
where:
s(t,x): step-function(330 for x=[0;2000])
(350 for x=[2000;3000])
(390 for x=[3000;4000])
I(t,x): Integral(exp(-B_hat/x(u))/C_hat)) from x=0 to t
beta_hat, C_hat and B_hat are known parameters
My MATLAB-script looks like that:
beta_hat = 4.2915822
B_hat = 1861.6186657
C_hat = 58.9848692
%% Step-function x(t)
syms t
y(t) = (exp(-B_hat/((heaviside(t)-heaviside(t-2000))*(330)+(heaviside(t-2000)-heaviside(t-3000))*(350)+...
(heaviside(t-3000)-heaviside(t-4000))*(390))))/C_hat;
fnum=matlabFunction(y);
Inum=@(x)integral(fnum,0,x);
f = @(x)(beta_hat*fnum(x).*Inum(x).^(beta_hat-1)).*exp(-(Inum(x).^beta_hat))
ezplot(f,[0,14000])
But if I plot my function f the figure isn´t right. There should be a smooth curve, similar to the bell-shaped curve.
Does anybody recognize my fault?Maxhttps://uk.mathworks.com/matlabcentral/profile/authors/4346765tag:uk.mathworks.com,2005:Question/8632052021-06-23T10:11:51Z2021-06-24T02:04:19ZHow to modify the y-axis tick label and tick values (2016a)I have three variables day, time and z2 and i plot using imagesc. Below are the data information:
data information:
day 1*1420 double(each number is equal to 6 hours)
time 1*3001 double (this case has -300:300 with interval of 0.2)
z2 1420*3001 double
Later I converted the weeks segments into date by using below code.
fig=figure(ii);
h1=subplot(3,1,1);
imagesc(time,day,z2);
colormap(jet)
YTickStr = char(datetime('10/10/2018', 'InputFormat', 'dd/MM/yy', 'Format', 'dd/MM/yy') + hours(day*6));
set(gca, 'YTick', 1:lengday, 'YTickLabel', YTickStr);
xlim([-100 100]);
If i do not use any interval, ticks label are so difficult to read as below and I cant read any thing
Later, I change the interval with 1:500:lengday and it starts from 1JAN which i exected to start from 10/10/18.
How can I modify the code so that it gives me the interval based on Ytrickstr?
here is my failed attemt which gives me the first 5 values from YTickStr.
yval = ylim(gca);
set(gca,'YTick',linspace(yval(1),yval(2),5),'YTickLabel', YTickStr)
YTickStr files is like this
10/10/18
10/10/18
10/10/18
11/10/18
11/10/18
11/10/18
11/10/18
12/10/18
12/10/18
12/10/18
12/10/18
13/10/18
13/10/18
13/10/18
13/10/18
14/10/18
Thank you very muchAAhttps://uk.mathworks.com/matlabcentral/profile/authors/20389342tag:uk.mathworks.com,2005:Question/8638202021-06-24T02:00:41Z2021-06-24T02:00:41Zsimulink did not generate code folderThe full path is C:\Users\DELL\Desktop\simulinkfold. I check the path which does not have some space(s), and still not succeed.chaozhen wanghttps://uk.mathworks.com/matlabcentral/profile/authors/22329952tag:uk.mathworks.com,2005:Question/8618902021-06-21T22:32:41Z2021-06-24T01:54:10ZReading text and data from excel I am trying to read in an excel file that has both text and numbers into matlab. Using xls read it does not give me all the text but some... Some of its shows up as Nan or Var1 Var2 ect... and same thing with readtable...Austin Matuszewskihttps://uk.mathworks.com/matlabcentral/profile/authors/17016166tag:uk.mathworks.com,2005:Question/8637752021-06-23T23:48:50Z2021-06-24T01:37:41Z?How do i get data from a table to use for further calculations
i would like to find the value in second, third and fourth column corresponding to a value (material name) of the first column in a table imported from Excel.
Jona Salabalijahttps://uk.mathworks.com/matlabcentral/profile/authors/22640044tag:uk.mathworks.com,2005:Question/8637852021-06-24T00:43:21Z2021-06-24T01:33:14ZIntegral of combined handle functions
I need to do a integral with a function by combining two functions, something like this:
syms q r
x(q,r) = q + 2*r;
y(q,r) = q*9 + r;
G = @(q,r) x+y
integral2(G,1,2,1,2)
It is only a example, my real problem is much more complex. How can i do that?Tiago Araujohttps://uk.mathworks.com/matlabcentral/profile/authors/22168692tag:uk.mathworks.com,2005:Question/8560552021-06-14T16:02:43Z2021-06-24T01:26:02ZGear ratio as output from CVT blockIs there a way by which I can take instantaneous gear ratio as output from CVT block available in the powertrain blockset ?Aditya Gandhihttps://uk.mathworks.com/matlabcentral/profile/authors/21006041tag:uk.mathworks.com,2005:Question/8636702021-06-23T20:01:43Z2021-06-24T01:16:10ZAccessing contents inside Nested cellI have a nested cell of the size 1x48 and there are multiple cells inside them as shown below in the screen shot. They are of variable length so some matlab functions like cell2mat is not working.
I want to store those values in a matrix one-by-one as per the order of the cells so that it can be easily written to excel files.
Here is my code that I have tried.
clc
e = edges;
e_size = size(e);
for i=1:1:e_size(1)
for j=1:1:e_size(2)
e_new=e{i,j};
end
end
edges is my nested cellKetan Shendehttps://uk.mathworks.com/matlabcentral/profile/authors/18953305tag:uk.mathworks.com,2005:Question/3142832016-11-28T05:49:22Z2021-06-24T01:15:08ZHow can I use TensorFlow library from matlab environment?I want to use or access TensorFlow library from Matlab environment, especially for machine learning. How can I use TensorFlow library from matlab ?K M Ibrahim Khalilullahhttps://uk.mathworks.com/matlabcentral/profile/authors/7463294tag:uk.mathworks.com,2005:Question/8637952021-06-24T01:09:35Z2021-06-24T01:09:35ZLoop to populate a 12 by 12 matrixHello Guys,
I am tryling to form a 12 by 12 matrix for 11 elements. I am getting some errors. Take a look at my code below: it looks perfect to me but it is not working
SC1=rand(11,11);% Test Data
SC2=rand(11,11);
SC3=rand(11,11);
SC4=rand(11,11);
SC5=rand(11,11);
SC6=rand(11,11);
SC7=rand(11,11);
SC8=rand(11,11);
n=size(SC8,1);
K1=zeros(12,1);
K2=zeros(12,1);
K3=zeros(12,1);
K4=zeros(12,1);
K5=zeros(12,1);
K6=zeros(12,1);
K7=zeros(12,1);
K8=zeros(12,1);
K9=zeros(12,1);
K10=zeros(12,1);
K11=zeros(12,1);
K12=zeros(12,1);
K=zeros(12,12);
for i=1:n
K1(i)=[SC1(i);0;0;0;0;0;-SC1(i);0;0;0;0;0];
K2(i)=[0;SC6(i);0;0;0;SC2(i);0;-SC6(i);0;0;0;SC2(i)];
K3(i)=[0;0;SC7(i);0;-SC3(i);0;0;0;-SC7(i);0;-SC3(i);0];
K4(i)=[0;0;0;SC4(i);0;0;0;0;0;-SC4(i);0;0];
K5(i)=[0;0;-SC3(i);0;(2*SC5(i));0;0;0;SC3(i);0;SC5(i);0];
K6(i)=[0;SC2(i);0;0;0;(2*SC8(i));0;-SC2(i);0;0;0;SC8(i)];
K7(i)=-K1;
K8(i)=-K2;
K9(i)=-K3;
K10(i)=-K4;
K11(i)=[0;0;-SC3(i);0;SC5(i);0;0;0;SC3(i);0;(2*SC5(i));0];
K12(i)=[0;SC2(i);0;0;0;SC8(i);0;SC2(i);0;0;0;(2*SC8(i))];
K(i)=[K1(i) K2(i) K3(i) K4(i) K5(i) K6(i) K7(i) K8(i) K9(i) K10(i) K11(i) K12(i)];
end
DARLINGTON ETAJEhttps://uk.mathworks.com/matlabcentral/profile/authors/8753940tag:uk.mathworks.com,2005:Question/8637802021-06-23T23:57:04Z2021-06-24T01:04:30ZImporting .vec filesI am trying to open multiple .vec files with importdata or readtable but it seems that this filetype is not supported. Is there any way to do this without having to convert the .vec files?Curtis Lamhttps://uk.mathworks.com/matlabcentral/profile/authors/21305119tag:uk.mathworks.com,2005:Question/8618052021-06-21T19:49:45Z2021-06-24T00:39:42ZHow can I read Fujifilm 3D .mpo files in 2021 (two jpeg)? Earlier solution code doesn't seem to work anymore.Hello,
I have thousands of Fujifilm 3D .mpo image files from their W3 camera that contain two jpeg images.
There is code in the File Exchange from 2014, but the imread function it uses doesn't seem to work as coded in MATLAB ver2020b.
Can anyone suggest an approach for reading these files to work with?
Thank you, DPDavid W Purcellhttps://uk.mathworks.com/matlabcentral/profile/authors/13133979tag:uk.mathworks.com,2005:Question/8632602021-06-23T11:51:08Z2021-06-24T00:37:32ZSimulink conditional breakpoint setting and continue in co-simulation with CANoeGreetings all, i have this problem haunted me for a long time, in my simulink model i want to add a break funtion which can stop the funtion running when the signal doesn't meet the condition but as the function running for a bit while, the signal may meet the condition again and in this point i'd like simulink continues recording from where it stopped. Below is what i want for the result, these three curves are the input signals from CANoe and i'd like to set several conditions to realize the function that i want. Question is how can i realize the desired result described in below? can anyone help me? many thanks!!
Song Lyuhttps://uk.mathworks.com/matlabcentral/profile/authors/22857620tag:uk.mathworks.com,2005:Question/555662012-12-03T19:29:01Z2021-06-24T00:35:15ZConvolutional Coding/Decoding Using Matlab FunctionsI'm trying to perform convolutional coding/decoding using built in Matlab functions. I'm trying to implement (2,1,3) code.
K=3;
G1=7;
G2=5;
msg=[1 1 0 0 1 0];
trel=poly2trellis(K,[G1 G2]);
coded=convenc(msg,trel);
decoded=vitdec(coded,trel,5*K,'cont','hard');
coded=[1 1 0 1 0 1 1 1 1 1 1 0]
decoded=[0 0 0 0 0 0]
As you would expect, the decoded message should be the same as msg, which it is not. I don't see where I have gone wrong in this simple example.Jaredhttps://uk.mathworks.com/matlabcentral/profile/authors/3116953tag:uk.mathworks.com,2005:Question/2836902016-05-11T10:12:17Z2021-06-24T00:31:15ZHow do I merge function handles?suppose I have 2 function handles to evaluate
for i=1:90
f= @(x)x^3*sin(i)
and
g=@(x)x^2*cos(i)
end
the functions i have are far more complicated.
now suppose i want to merge them to obtain f+g, i.e. a single function
@(x)x^3sin(i)+x^2cos(i).
How can i do that without combining the expressions but only using f and g?
thanks for the helpRiccardo Pinzihttps://uk.mathworks.com/matlabcentral/profile/authors/7737815tag:uk.mathworks.com,2005:Question/8636852021-06-23T20:10:47Z2021-06-24T00:30:27ZHow to import these text files with all their informationHello, I have been trying to import these two text files into matlab without much success. Either they are imported partially or not at all with the readvars and readtable functions. These two texts files are also formatted the same way, so I am not sure why they are being imported in different ways. My goal is to import many of these types of files into matlab, and I am having issues with only these two at the moment.
[A]=readvars('Data05449.txt','FileType','text')
[B]=readvars('Data05383.txt,'FileType','text')
[C]=readtable('Data05449.txt,'FileType','text')
[D]=readtable('Data05383.txt,'FileType','text')
As you run this you will see that it is not consistently importing into matlab. All of these files have the same format, so is there a way to get this to work? Thanks again
Ledgehttps://uk.mathworks.com/matlabcentral/profile/authors/15817887tag:uk.mathworks.com,2005:Question/8632352021-06-23T10:48:47Z2021-06-24T00:29:40ZHow to extract area using inpolygonHello everyone,
I need to do analysis on just rectangular part of my figure 1 (shown in black). Therefore, I tried to extract that area using inpolygon. My data is lat = 406x270 and lon = 406x270. I have plotted temperature which is 2030x1354.
Figure 1:
Using the code below produced figure 2:
xv= [104.61, 102.98, 109.37, 109.52];
yv = [19.93, 25.03, 25.01, 19.98];
in = inpolygon(lon,lat,xv,yv);
figure
plot(xv,yv) % polygon
axis equal
hold on
plot(lon(in),lat(in),'r+') % points inside
plot(lon(~in),lat(~in),'bo') % points outside
hold off
I just can't figure out what is wrong in my code. Kindly tell me what's wrong here? Thank you.IMChttps://uk.mathworks.com/matlabcentral/profile/authors/16183559tag:uk.mathworks.com,2005:Question/8636602021-06-23T19:57:10Z2021-06-24T00:29:31ZLag from multiple live plots of serial dataHey matlab people, I'm working on plotting several outputs from Honeywell pressure sensors hooked up to my arduino mega. Currently I am running all data scanning and plotting through a while loop and using drawnow to plot the data at the end. My issue is that with 1 graph and even 2 graphs I can see the changes in pressure in real time with minimal delay/lag. Once I add the third graph the delay grows exponentially into almost 10-15 seconds for a response time. I would like to be able to at least read 4 at a time, but I really need this data to be in real time for my experiment. Here is my code below, thanks.
i = 1;
ii = 1;
iii = 1;
fscanf(s)
while(1)
scan = fscanf(s);
sscan = sscanf(scan, '%f');
if i <= 102 && numel(sscan) == 8
subplot(2,2,1);
pressure1(i) = sscan(1);
plot(pressure1);
axis([0 102 0 150]);
i = i+1;
elseif i > 102 && numel(sscan) == 8
subplot(2,2,1);
pressure1(1) = [];
pressure1(103) = sscan(1);
plot(pressure1(end-102:end));
axis([0 102 0 150]);
i = 103;
else
subplot(2,2,1);
pressure1(1) = [];
pressure1(103) = 0;
plot(pressure1(end-102:end));
axis([0 102 0 150]);
i = 103;
end
%pressure2
if ii <= 102 && numel(sscan) == 8
subplot(2,2,2);
pressure2(ii) = sscan(2);
plot(pressure2);
axis([0 102 0 150]);
ii = ii+1;
elseif ii > 102 && numel(sscan) == 8
subplot(2,2,2);
pressure2(1) = [];
pressure2(103) = sscan(2);
plot(pressure2(end-102:end));
axis([0 102 0 150]);
ii = 103;
else
subplot(2,2,2);
pressure2(1) = [];
pressure2(103) = 0;
plot(pressure2(end-102:end));
axis([0 102 0 150]);
ii = 103;
end
%pressure3
if iii <= 102 && numel(sscan) == 8
subplot(2,2,3);
pressure3(iii) = sscan(3);
plot(pressure3);
axis([0 102 0 150]);
iii = iii+1;
elseif iii > 102 && numel(sscan) == 8
subplot(2,2,3);
pressure3(1) = [];
pressure3(103) = sscan(3);
plot(pressure3(end-102:end));
axis([0 102 0 150]);
iii = 103;
else
subplot(2,2,3);
pressure3(1) = [];
pressure3(103) = 0;
plot(pressure3(end-102:end));
axis([0 102 0 150]);
iii = 103;
end
drawnow
end
Thomas Fairhttps://uk.mathworks.com/matlabcentral/profile/authors/11902355tag:uk.mathworks.com,2005:Question/5815012020-08-19T05:44:56Z2021-06-24T00:27:30Zhow to send thingspeak data to matlabactually i want to send data of thingspeak to matlab.the sensors data i have already uploaded on thingspeak by the aurdino IDE and use of esp32 that data i just want to send to matlab.so how to do that?Maryam saeedhttps://uk.mathworks.com/matlabcentral/profile/authors/14292194tag:uk.mathworks.com,2005:Question/8628102021-06-22T20:59:31Z2021-06-24T00:24:51ZSkip the optimised parameters result if the objective function failsHi
I am using matlab "isqnonlin" and "gamultiobj" (in two different codes) in matlab to optimise six parameters.
My objective function, is a function that calls ABAQUS and run some finite element models (FEMs) and export the result into matlab and matlab should optimised some coficient.
In some cases, matlab uses some coeficient that when the ABAQUS uses them to export the result, the FEM does not converge and it exists unfinished and matlab exports the results and generates the new optimised parametrs based on those unfinished data, which result in inaccurate optimisation.
My question is:
How can I define a condition that, if the condition was true MATLAB would ignore the esimated paramerts and goes to next iteration and estimates new parametrs?
ThanksSMhttps://uk.mathworks.com/matlabcentral/profile/authors/10908668tag:uk.mathworks.com,2005:Question/857412013-08-27T17:26:44Z2021-06-24T00:15:32ZImwrite with display rangeI want to save image as *.tiff with its *.tfw for georeference in ArcMap. The problem occures because I need my image to look excatly like the image that I
create with imshow in figure, where I set the display range.
Is it possible to imwrite image with prefered display range?
thanksAleksanderhttps://uk.mathworks.com/matlabcentral/profile/authors/4498128tag:uk.mathworks.com,2005:Question/8637502021-06-23T22:14:30Z2021-06-24T00:06:20ZHow can I change a daily temperature dataset to yearly group. Hi, please help me. I have a gridded temperature data containing daily temperature from 1970 - 2014, taken from 1600 grid points. How can I change it from daily temp. data to annual temperature data, so I can perform a time series analysis for the various years. Thank youLemea Akarahttps://uk.mathworks.com/matlabcentral/profile/authors/22538543tag:uk.mathworks.com,2005:Question/8629352021-06-23T03:39:11Z2021-06-24T00:02:45Zfinite volume method for 1D unsteady heat conduction Hey All,
I am trying to simulate unsteady 1D heat conduction equation using MATLAB, I am following the instructions in the following link with changing one of the boundary conditions (West BC): https://www.youtube.com/watch?v=h3bHAEN7t6M. I also added heat to my equations, since I have heat generation for one of the three layers I have. The code runs normally for the first 500ish iterations, and then the plotted temperature suddenly disappears. Does this issue appear because of the values I'm feeding to the code or it is the convergence approach (lines 101-143)?
P.S
Even for the initial iterations, the temperature value appears insanely high
clear;close all;clc
Dvi=0.246926*2; %ID of vessel (m)
Dvo=0.67*2; %OD of vessel (m)
Dins=0.797*2; %OD of insulation (m)
Dhyd=0.2; %hydraulic diameter of the coolant (air, in m)
L=1.4; %height of everything (m)
%Volume Descritizations [salt, vessel wall, insulator]
Discs=[50 30 10];
dx=[(0.5*Dvi)/Discs(1)...
(0.5*(Dvo-Dvi))/Discs(2)...
(0.5*(Dins-Dvo))/Discs(3)]; %Spatial increment (dx)
Ac= 0.25.*pi*dx.^2; %Cross-sectinal area
%Time descritization
dt=10; %time increment (sec)
t=1:dt:1000; %time vector (sec)
%Heat rate
q=120975.*t.^-0.293;
%Thermal properties of salt
cps=4683718.0; %specific heat (J/m3-K)
rhov=8e3; %density (kg/m3)
cpv=490; %heat capacity for SS304
cpins=144640; %specific heat (J/m3-K)
%Thermal conductivities
kins=0.15; %W/m-K
kv=14; %W/m-K
ks=20; %W/m-K
%Coolant (air) temperature initialization
T0 =100; %T initial
Tinf=300; %temperature of air (K)
hinf=12; %assumed (W/m2-K)
Rinf=1/(hinf*pi*Dhyd*L); %Thermal resistance due to convection in coolant
K_a = 26.24; %Thermal conductivity of the air
Cp_a = 1e3; %heat capacity for the air
rho_a = 1.184; %density of the air
mu_a = 18.6e-6; %dynamic viscosity of the air
nu = mu_a/rho_a;
pr_a = mu_a*Cp_a/K_a; %prandtl number for the salt
g = 9.81;
alp=K_a/rho_a*Cp_a;
beta=3.32e-3; %expansion coefficient puuled out of the reference
%% Constructing the A matrix
A=eye(sum(Discs));
%%%%%%%%%%%%%%%%INPUTS
Adiag_ins=-(2*kins*Ac(3)./dx(3) + cpins*Ac(3)*dx(3)./dt);
A_offDiag_ins=kins*Ac(3)./dx(3);
Adiag_v=-(2*kv*Ac(2)./dx(2) + rhov*cpv*Ac(2)*dx(2)./dt);
A_offDiag_v=kv*Ac(2)./dx(2);
Adiag_s=-(2*ks*Ac(1)./dx(1) + cps*Ac(1)*dx(1)./dt);
A_offDiag_s=ks*Ac(1)./dx(1);
%%%%%%%%%%%%%%%%
for i=1:Discs(3)
A(i,i)=Adiag_ins;
[A(i,i+1),A(i+1,i)]=deal(A_offDiag_ins);
end
% A(Discs(3),Discs(3)-1)=A_offDiag_v;
for i=Discs(3):sum([Discs(3) Discs(2)])
A(i,i)=Adiag_v;
[A(i,i+1),A(i+1,i)]=deal(A_offDiag_v);
end
% A(sum([Discs(3) Discs(2)]),sum([Discs(3) Discs(2)])-1)=A_offDiag_s;
for i=sum([Discs(3) Discs(2)]):sum(Discs)-1
A(i,i)=Adiag_s;
[A(i,i+1),A(i+1,i)]=deal(A_offDiag_s);
end
% A(i+1,i+1)=Adiag_s;
A=rot90(A,2);
A(1,1)=-(ks*Ac(1)./dx(1) + cps*Ac(1)*dx(1)./(2*dt));
A(end,end)=-(kins*Ac(3)./dx(3) + cpins*Ac(3)*dx(3)./(2*dt));
% imagesc(A); colormap jet
%% Solving for temperature
T=zeros(sum(Discs),length(t))+Tinf;
ResidualTolerance=0.1;
close all;clc
figure('Units','inches','Position',[1 1 10 5]); hold on
for i=1:length(t)-1
ct=0; TMax = 500;
while abs(max(T(:,i+1))-TMax)>ResidualTolerance
ct=ct+1;
TMax=max(T(:,i+1));
%%%%%%%%%%%%%%%%INPUTS
B_s=-q(i)-(cps*Ac(1)*dx(1)./dt);
B_v=-(rhov*cpv*Ac(2)*dx(2)./dt);
B_ins=-(cpins*Ac(3)*dx(3)./dt);
%%%%%%%%%%%%%%%%BMatrix
BConst=[repmat(B_s,[Discs(1),1]) ; ...
repmat(B_v,[Discs(2),1]) ; ...
repmat(B_ins,[Discs(3),1])];
%%%%%%%%%%Boundaries for vector b
B_boundary1=-q(i)-((cps*Ac(1)*dx(1)./(2*dt))*TMax);
B_boundary2=-((cpins*Ac(3)*dx(3)./(2*dt))*T(end,i))-(hinf*Ac(3)*Tinf);
B(:,i)=T(:,i).*BConst;
B(1,i)=B_boundary1;
B(end,i)=B_boundary2;
% C = inv(A);
T(:,i+1)=A\B(:,i);
Ra=(g.*beta./(nu*alp)).*(Tinf-T(end,i+1)).*(Dhyd^3); %initial guess for Ra
Nu=(0.825+(0.387*Ra.^(1/6))/(1+(0.492/pr_a).^(9/16)).^(8/27)).^2;
h=Nu.*K_a./Dhyd;
Rinf=1/(hinf*pi*Dhyd*L); %Thermal resistance due to convection in coolant
Tinf=-(Rinf*q(i))+T(end,i+1);
end
disp([i ct])
cla;
plot(T(:,i+1),'k');
ylabel('$T$','Interpreter','latex');
pause(0.1)
title(num2str(t(i+1)));
end
hold off;Laith Zaidanhttps://uk.mathworks.com/matlabcentral/profile/authors/16158016tag:uk.mathworks.com,2005:Question/8621452021-06-22T07:32:32Z2021-06-23T23:54:20ZHow can I perform a chi-square test to determine if accept or reject the null hypothesisAs an example, we have the two groups, the first group (total 30 people) has 7 members that has allergy to a material, and 23 members that do not have allergy to the same material. Than, the second group (total 20 people) has 15 members that has allergy another material, and 5 members that do not have allergy to the second material.
How can I perform a chi-square test to evalueate if allergy depend on material, with alpha = 0.01?lab mathttps://uk.mathworks.com/matlabcentral/profile/authors/22884304tag:uk.mathworks.com,2005:Question/8637702021-06-23T23:41:49Z2021-06-23T23:42:35Zhow to find position ?Hello
I'm programming this is my simulator:
x = 5:1:6; y = 7:1:8; x1=62:1:63; y1=61:1:62 ; x2=21:1:22; y2=11:1:12;
[z,v] = test(x, y,x1,y1,x2,y2); % myfunction
C1 = reshape(z,[ ],size(z,2),1); % change matrix dimensions 6D to 2D
C2 = reshape(v,[ ],size(v,2),1); % change matrix dimensions 6D to 2D
C = [C1,C2]; % size 32*4
U = reshape(C,64,2); % size 64*2
frr = reshape(U,32,4); % size 32*2
fr1 = frr(:, 1:2); % split matrix
fr2 = frr(:, 3:4); % split matrix
A = reshape(fr1,[2,2,2,2,2,2]) % change matrix dimensions 2D to 6D
B = reshape(fr2,[2,2,2,2,2,2]) % change matrix dimensions 2D to 6D
V =1.0e+04 * 4.6874; %find the minimum
dif = abs(A-V);
[minf, iLinear] = min(dif(:));
[i1, i2, i3, i4, i5,i6] = ind2sub(size(dif), iLinear) %find the position of that value
x (i1)
y (i2)
x1(i3)
y1(i4)
x2(i5)
y2(i6)
In conclusion . I have a 6D input. (2,2,2,2,2,2) I converted it to 2D.(to do something) I converted it back to 6D as before. I'm not sure. I find the minimum and its position.I will get the correct value. would you recommend what I could do?
Thank you for your kindness.Yan Kethttps://uk.mathworks.com/matlabcentral/profile/authors/22886630tag:uk.mathworks.com,2005:Question/8637652021-06-23T23:40:31Z2021-06-23T23:40:31ZSolving a set of equations in cell arraysHi, I have a 10*10 cell array that each cell contains a 4*4 matrix. The code for this part is (credit to Stephen Cobeldick for the code):
x1 = rand(10,10);
y1 = rand(10,10);
z1 = rand(10,10);
r1 = rand(10,10);
a1 = cat(3,x1,y1,z1,r1);
x2 = rand(10,10);
y2 = rand(10,10);
z2 = rand(10,10);
r2 = rand(10,10);
a2 = cat(4,x2,y2,z2,r2);
tmp = num2cell(sqrt(a1./a2),3:4);
fun = @(a)reshape(a,4,4);
out = cellfun(fun,tmp,'uni',0)
now I want to calculate a set of equations that would be equal to the results that I get from each of the element of the matrix in each cell. The set of equation that needs to be solved is:
a=-0.5; b=1;
out{1}(1,1)=a*X + (1-a)*Y;
out{1}(1,1)=b*X + (1-b)*Y
That would result in one X and one Y for each of element of the matrix in the cells (that would result in a 10*10 cell, within each cell a 4*4 cell and each cell has a 2*1 or 1*2 vector).
I want to do this for every element of the matrices in each cell (out{1}(1,2), out{1}(1,3), ...) so that I would have a 10*10 cell array, each cell with 4*4 cells and each cell has 2 values corresponding to the results from the “out”.
Could someone please help me with this part, I'd really appreciate it. My code is already a long and convoluted one and I need to concise it as much as possible; I used some for loops but didn't get the desired answer.
Thank you.MarshallSchttps://uk.mathworks.com/matlabcentral/profile/authors/19310906tag:uk.mathworks.com,2005:Question/8635752021-06-23T17:40:50Z2021-06-23T23:39:11ZMatlab and 'sandbox' process Peak CPU Usage in macOS Big SurMatlab version: 9.10.0.1684407 (R2021a) Update 3'
System Version: Big Sur 11.4 (20F71)
MacBook Pro: (13-inch, 2020, Four Thunderbolt 3 ports)
Processor: 2 GHz Quad-Core Intel Core i5
Memory: 16 GB 3733 MHz LPDDR4X
Graphics card: Intel Iris Plus Graphics 1536 MB
Problem:
In the image bellow I pressed command+return to run the code and the sandboxed process started to peak. This happens all the time while using matlab. Sometimes even when just typing in in the code editor. I even tried closing all other applications in the system and run just Matlab, the problem persisted.
From time to time the sandboxd process peaks CPU usage and the entire Matlab becomes laggy, impossible to use. It is a recurrent problem. I tried installing 2020b version, but same thing happened. I'm not using Magnet or other window snaping tool.
I've sent a feedback to Mathworks under this identifier when it happened to froze once, forcing me to quit the application: Help troubleshooting recent MATLAB crash: 04938298 ref:_00Di0Ha1u._5003q1PuOu8:refJoao Nizerhttps://uk.mathworks.com/matlabcentral/profile/authors/14953487tag:uk.mathworks.com,2005:Question/8637202021-06-23T20:44:24Z2021-06-23T23:33:40ZHow to define both integer and decimal increment in one for loop?Hi all,
I would like to define one for loop that goes from 0 to 1 with an increment of 0.1 and then goes from 1 to 30 by an increment of 2, i.e., combination of the following two loops. Is it possible? If so, how?
for n = 1:2:30
f(round((n-1)/2+1)) = ....
end
z = 0: 0.1: 1;
for n = 1: length(z)
f(n) = ..
end
Thanks in advance
Susanhttps://uk.mathworks.com/matlabcentral/profile/authors/15596863tag:uk.mathworks.com,2005:Question/8637452021-06-23T21:59:48Z2021-06-23T23:26:26ZCustomizing the tick values and labels along x axisHi All,
When I plot(1:20, f), the x-axis are shown from 1 to 20. However my real x values are
x =
Columns 1 through 13
30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000
Columns 14 through 20
4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000
and I'd like the real x values to show up in the figure. To do so, I used
xticks([x])
and got an error that says
Value must be a numeric vector whose values increase.
Any idea how I can fix this issue?
Thanks in advance
Susanhttps://uk.mathworks.com/matlabcentral/profile/authors/15596863tag:uk.mathworks.com,2005:Question/8632952021-06-23T12:26:20Z2021-06-23T23:22:08Zhow can i write function with the picture which i attached to the question?hey people
have a good time
i have a problem over the function which i attached to this Question.
i would like to write the function which take 2 variables (e.g. t and o)
and compute rmse and r^2 coefficient
can you help me out over this problem?
hadi mehttps://uk.mathworks.com/matlabcentral/profile/authors/22283975