https://uk.mathworks.com/matlabcentral/answers/questions MATLAB Answers — New Questions 2021-06-24T03:14:51Z tag:uk.mathworks.com,2005:Question/862855 2021-06-22T23:54:18Z 2021-06-24T03:14:51Z chirp with carrier frequency using LinearFMWaveform Hello, 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. Katia Katia https://uk.mathworks.com/matlabcentral/profile/authors/1921416 tag:uk.mathworks.com,2005:Question/861140 2021-06-21T04:55:08Z 2021-06-24T03:11:24Z Find 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 agrawal https://uk.mathworks.com/matlabcentral/profile/authors/19809179 tag:uk.mathworks.com,2005:Question/863810 2021-06-24T01:32:22Z 2021-06-24T03:08:54Z how 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 navi https://uk.mathworks.com/matlabcentral/profile/authors/11695462 tag:uk.mathworks.com,2005:Question/863045 2021-06-23T06:39:57Z 2021-06-24T03:06:41Z Hello, 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 ARIS https://uk.mathworks.com/matlabcentral/profile/authors/22889241 tag:uk.mathworks.com,2005:Question/863840 2021-06-24T02:17:01Z 2021-06-24T03:04:55Z Create a row vector Create a row vector named x that starts at 1, ends at 10, and contains 5 elements. Francis Adams Kwofie https://uk.mathworks.com/matlabcentral/profile/authors/22895856 tag:uk.mathworks.com,2005:Question/863805 2021-06-24T01:29:42Z 2021-06-24T03:03:45Z Extract the center blob of an image I'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 A https://uk.mathworks.com/matlabcentral/profile/authors/6199341 tag:uk.mathworks.com,2005:Question/863860 2021-06-24T02:57:41Z 2021-06-24T02:57:41Z How 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 you Khan https://uk.mathworks.com/matlabcentral/profile/authors/21229238 tag:uk.mathworks.com,2005:Question/863845 2021-06-24T02:20:32Z 2021-06-24T02:55:49Z Matlab plot command function Plot 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. ver Student https://uk.mathworks.com/matlabcentral/profile/authors/22903246 tag:uk.mathworks.com,2005:Question/863855 2021-06-24T02:53:33Z 2021-06-24T02:53:33Z How 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 Hewitt https://uk.mathworks.com/matlabcentral/profile/authors/22713756 tag:uk.mathworks.com,2005:Question/862020 2021-06-22T04:13:37Z 2021-06-24T02:51:40Z Parallel processing remote and server logs collection / scp I 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! Jogger https://uk.mathworks.com/matlabcentral/profile/authors/7949204 tag:uk.mathworks.com,2005:Question/860905 2021-06-20T17:53:07Z 2021-06-24T02:47:12Z how 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. NN https://uk.mathworks.com/matlabcentral/profile/authors/15064601 tag:uk.mathworks.com,2005:Question/452413 2019-03-26T09:29:58Z 2021-06-24T02:37:46Z Simulink- error in hydraulic simulation Hi 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 caravita https://uk.mathworks.com/matlabcentral/profile/authors/5068127 tag:uk.mathworks.com,2005:Question/850190 2021-06-07T18:29:45Z 2021-06-24T02:26:57Z Add 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 Vaidya https://uk.mathworks.com/matlabcentral/profile/authors/16218757 tag:uk.mathworks.com,2005:Question/863850 2021-06-24T02:23:58Z 2021-06-24T02:23:58Z graph wont display on a simple code helo 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; end Wan Muhammad Haikal Bin Wan Mohd Nadzri https://uk.mathworks.com/matlabcentral/profile/authors/21413833 tag:uk.mathworks.com,2005:Question/863735 2021-06-23T21:31:56Z 2021-06-24T02:21:48Z Create a Loop for this process I 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 end DARLINGTON ETAJE https://uk.mathworks.com/matlabcentral/profile/authors/8753940 tag:uk.mathworks.com,2005:Question/863825 2021-06-24T02:02:30Z 2021-06-24T02:19:33Z Print Out Txt File Column Data Hi, 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 Hardyn https://uk.mathworks.com/matlabcentral/profile/authors/19686611 tag:uk.mathworks.com,2005:Question/480796 2019-09-17T15:16:16Z 2021-06-24T02:15:01Z Not responding on startup, macOS Mojave I 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 Smith https://uk.mathworks.com/matlabcentral/profile/authors/3990217 tag:uk.mathworks.com,2005:Question/863580 2021-06-23T17:48:52Z 2021-06-24T02:10:49Z could anyone help me to solve the issue in the following command when 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 navi https://uk.mathworks.com/matlabcentral/profile/authors/11695462 tag:uk.mathworks.com,2005:Question/863835 2021-06-24T02:07:55Z 2021-06-24T02:07:55Z Is 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. Sparks https://uk.mathworks.com/matlabcentral/profile/authors/7850894 tag:uk.mathworks.com,2005:Question/863830 2021-06-24T02:05:36Z 2021-06-24T02:05:36Z how 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 wang https://uk.mathworks.com/matlabcentral/profile/authors/22329952 tag:uk.mathworks.com,2005:Question/264762 2016-01-22T08:23:45Z 2021-06-24T02:04:31Z How 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? Max https://uk.mathworks.com/matlabcentral/profile/authors/4346765 tag:uk.mathworks.com,2005:Question/863205 2021-06-23T10:11:51Z 2021-06-24T02:04:19Z How 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 much AA https://uk.mathworks.com/matlabcentral/profile/authors/20389342 tag:uk.mathworks.com,2005:Question/863820 2021-06-24T02:00:41Z 2021-06-24T02:00:41Z simulink did not generate code folder The full path is C:\Users\DELL\Desktop\simulinkfold. I check the path which does not have some space(s), and still not succeed. chaozhen wang https://uk.mathworks.com/matlabcentral/profile/authors/22329952 tag:uk.mathworks.com,2005:Question/861890 2021-06-21T22:32:41Z 2021-06-24T01:54:10Z Reading 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 Matuszewski https://uk.mathworks.com/matlabcentral/profile/authors/17016166 tag:uk.mathworks.com,2005:Question/863775 2021-06-23T23:48:50Z 2021-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 Salabalija https://uk.mathworks.com/matlabcentral/profile/authors/22640044 tag:uk.mathworks.com,2005:Question/863785 2021-06-24T00:43:21Z 2021-06-24T01:33:14Z Integral 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 Araujo https://uk.mathworks.com/matlabcentral/profile/authors/22168692 tag:uk.mathworks.com,2005:Question/856055 2021-06-14T16:02:43Z 2021-06-24T01:26:02Z Gear ratio as output from CVT block Is there a way by which I can take instantaneous gear ratio as output from CVT block available in the powertrain blockset ? Aditya Gandhi https://uk.mathworks.com/matlabcentral/profile/authors/21006041 tag:uk.mathworks.com,2005:Question/863670 2021-06-23T20:01:43Z 2021-06-24T01:16:10Z Accessing contents inside Nested cell I 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 cell Ketan Shende https://uk.mathworks.com/matlabcentral/profile/authors/18953305 tag:uk.mathworks.com,2005:Question/314283 2016-11-28T05:49:22Z 2021-06-24T01:15:08Z How 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 Khalilullah https://uk.mathworks.com/matlabcentral/profile/authors/7463294 tag:uk.mathworks.com,2005:Question/863795 2021-06-24T01:09:35Z 2021-06-24T01:09:35Z Loop to populate a 12 by 12 matrix Hello 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 ETAJE https://uk.mathworks.com/matlabcentral/profile/authors/8753940 tag:uk.mathworks.com,2005:Question/863780 2021-06-23T23:57:04Z 2021-06-24T01:04:30Z Importing .vec files I 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 Lam https://uk.mathworks.com/matlabcentral/profile/authors/21305119 tag:uk.mathworks.com,2005:Question/861805 2021-06-21T19:49:45Z 2021-06-24T00:39:42Z How 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, DP David W Purcell https://uk.mathworks.com/matlabcentral/profile/authors/13133979 tag:uk.mathworks.com,2005:Question/863260 2021-06-23T11:51:08Z 2021-06-24T00:37:32Z Simulink conditional breakpoint setting and continue in co-simulation with CANoe Greetings 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 Lyu https://uk.mathworks.com/matlabcentral/profile/authors/22857620 tag:uk.mathworks.com,2005:Question/55566 2012-12-03T19:29:01Z 2021-06-24T00:35:15Z Convolutional Coding/Decoding Using Matlab Functions I'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. Jared https://uk.mathworks.com/matlabcentral/profile/authors/3116953 tag:uk.mathworks.com,2005:Question/283690 2016-05-11T10:12:17Z 2021-06-24T00:31:15Z How 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 help Riccardo Pinzi https://uk.mathworks.com/matlabcentral/profile/authors/7737815 tag:uk.mathworks.com,2005:Question/863685 2021-06-23T20:10:47Z 2021-06-24T00:30:27Z How to import these text files with all their information Hello, 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 Ledge https://uk.mathworks.com/matlabcentral/profile/authors/15817887 tag:uk.mathworks.com,2005:Question/863235 2021-06-23T10:48:47Z 2021-06-24T00:29:40Z How to extract area using inpolygon Hello 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. IMC https://uk.mathworks.com/matlabcentral/profile/authors/16183559 tag:uk.mathworks.com,2005:Question/863660 2021-06-23T19:57:10Z 2021-06-24T00:29:31Z Lag from multiple live plots of serial data Hey 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 Fair https://uk.mathworks.com/matlabcentral/profile/authors/11902355 tag:uk.mathworks.com,2005:Question/581501 2020-08-19T05:44:56Z 2021-06-24T00:27:30Z how to send thingspeak data to matlab actually 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 saeed https://uk.mathworks.com/matlabcentral/profile/authors/14292194 tag:uk.mathworks.com,2005:Question/862810 2021-06-22T20:59:31Z 2021-06-24T00:24:51Z Skip the optimised parameters result if the objective function fails Hi 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? Thanks SM https://uk.mathworks.com/matlabcentral/profile/authors/10908668 tag:uk.mathworks.com,2005:Question/85741 2013-08-27T17:26:44Z 2021-06-24T00:15:32Z Imwrite with display range I 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? thanks Aleksander https://uk.mathworks.com/matlabcentral/profile/authors/4498128 tag:uk.mathworks.com,2005:Question/863750 2021-06-23T22:14:30Z 2021-06-24T00:06:20Z How 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 you Lemea Akara https://uk.mathworks.com/matlabcentral/profile/authors/22538543 tag:uk.mathworks.com,2005:Question/862935 2021-06-23T03:39:11Z 2021-06-24T00:02:45Z finite 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 Zaidan https://uk.mathworks.com/matlabcentral/profile/authors/16158016 tag:uk.mathworks.com,2005:Question/862145 2021-06-22T07:32:32Z 2021-06-23T23:54:20Z How can I perform a chi-square test to determine if accept or reject the null hypothesis As 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 mat https://uk.mathworks.com/matlabcentral/profile/authors/22884304 tag:uk.mathworks.com,2005:Question/863770 2021-06-23T23:41:49Z 2021-06-23T23:42:35Z how 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 Ket https://uk.mathworks.com/matlabcentral/profile/authors/22886630 tag:uk.mathworks.com,2005:Question/863765 2021-06-23T23:40:31Z 2021-06-23T23:40:31Z Solving a set of equations in cell arrays Hi, 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. MarshallSc https://uk.mathworks.com/matlabcentral/profile/authors/19310906 tag:uk.mathworks.com,2005:Question/863575 2021-06-23T17:40:50Z 2021-06-23T23:39:11Z Matlab and 'sandbox' process Peak CPU Usage in macOS Big Sur Matlab 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:ref Joao Nizer https://uk.mathworks.com/matlabcentral/profile/authors/14953487 tag:uk.mathworks.com,2005:Question/863720 2021-06-23T20:44:24Z 2021-06-23T23:33:40Z How 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 Susan https://uk.mathworks.com/matlabcentral/profile/authors/15596863 tag:uk.mathworks.com,2005:Question/863745 2021-06-23T21:59:48Z 2021-06-23T23:26:26Z Customizing the tick values and labels along x axis Hi 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 Susan https://uk.mathworks.com/matlabcentral/profile/authors/15596863 tag:uk.mathworks.com,2005:Question/863295 2021-06-23T12:26:20Z 2021-06-23T23:22:08Z how 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 me https://uk.mathworks.com/matlabcentral/profile/authors/22283975