https://fr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-08-05T22:44:44Ztag:fr.mathworks.com,2005:Question/5758182020-08-05T22:39:50Z2020-08-05T22:44:44Zextract mth and m+1st largest element from a vectormaxk find the largest elements of an array. Then, is there a function that allows to extract a general mth and m+1st highest element from a vector. Is using sort is the best way?alpedhuezhttps://fr.mathworks.com/matlabcentral/profile/authors/10930090tag:fr.mathworks.com,2005:Question/5757972020-08-05T21:45:54Z2020-08-05T22:43:26ZHow can I plot and reach to this figure ?
I want to know the code that can I get same figure about Biorhythms ?
A) write a MATLAB code that can display Biorhythms for a person given their date of birth and the target date. Your Program should be able to plot the Biorhythms for a suitable spread around the target date (i.e., 30 days).
B) Annotation of the plot and curve with day and date.
C) Create a User‐Defined function to Calculate the total number of days between birthdate and target date. Create your own logic. Do not use any built‐in function (i.e., datenum) to calculate the total number of days
D) Demonstration of features that you have created/coded to add value to graph. · Demonstration that code works correctly using representative samples.Khalid Sultanhttps://fr.mathworks.com/matlabcentral/profile/authors/18872987tag:fr.mathworks.com,2005:Question/3095412016-10-27T20:56:36Z2020-08-05T22:41:08ZHow can i convert image sequence to video i have 5 images and i want to see them as a video what should i do?alireza kooshafarhttps://fr.mathworks.com/matlabcentral/profile/authors/7278011tag:fr.mathworks.com,2005:Question/4095232018-07-09T20:31:20Z2020-08-05T22:40:58Zrunning matlab using command lineI am running matlab using Command line and using the following command to run the matlab.
"C:\Program Files\MATLAB\R2017b\bin\matlab.exe" -nodisplay -nosplash - nodesktop -r "run('Main.m');"
What should I add to this command to make sure Matlab doesn't get open and it just runs behind the scene and close automatically? Jackhttps://fr.mathworks.com/matlabcentral/profile/authors/498815tag:fr.mathworks.com,2005:Question/5758122020-08-05T22:34:29Z2020-08-05T22:40:22ZHow to write a multi line string? I want to print the following with all the characters in a file. I thought of using strvcat for this as it is a multiline string.
tran_models = strvcat({'.MODEL pcg PMOS( LEVEL=1 VTO=-0.45 KP=11.9 GAMMA=1.24 ',
'+ PHI=.75 LAMBDA=386u RD=21.0m RS=21.0m ',
'+ IS=750f PB=0.800 MJ=0.460 CBD=81.1p ',
'+ CBS=97.4p CGSO=720n CGDO=600n CGBO=1.88u )'});
fprintf(File,'%s\n', tran_models);
I have been trying to work around with this, but doesn't seem to work.
Output:
.+++M OPICDHSBEI=SL=7= .59p707c5f.g 4 p LP PAB MM=COB0G
SD.S/A8O(=0= 307L8 2E6M0VuJnE = LR0C=D.G1=4D 26OV10=T. 6O0C0=mB0- Dn0R= .S8C4=1G52.B 11OK.p=P0 1=m .1 81 8. u9...
It is printing the 1st column of vertical characters.
Thank you in advance.Jaykumar Vaidyahttps://fr.mathworks.com/matlabcentral/profile/authors/16218757tag:fr.mathworks.com,2005:Question/5757822020-08-05T20:47:14Z2020-08-05T22:36:24ZHi!, I have a csv file with an array of (405x91) dimensions and i need to plot in a GUI AXES the value of some (x,y) of this csv, how i can do this? I have an array of 405x91 . In my GUI (i made it from guide) i have a button and two editboxes and i need that when i press the button "next", the axes shows the value of the array(editbox1,editbox2). I will give you the picture so you can understand better:
So, if kpos=2 and ipos=1, then i need to plot the value of array(2,1) . This array is in the workspace but if i call it from the button callback it doesnt recognize the array. I need to know how to call a variable which is in my workspace and use it in my GUI code.
Help me please! Im stuck with this simple thing. Thanks!Santiago Villamilhttps://fr.mathworks.com/matlabcentral/profile/authors/14261191tag:fr.mathworks.com,2005:Question/5758152020-08-05T22:35:41Z2020-08-05T22:35:41ZHow could I read a single cell of an .csv file using readmatrix function with import options?Hello to everyone, I need to process different data from a .csv file. I do ask for the user what are the row ranges that need to read the code, with that, I need to save a value from a particular cell from the spreadsheet.
Next work very well for me. But I would like to know if it's possible to make this using import options.
kappa = readmatrix('1_5B_2.csv', 'Range', 'D6:D6');
Thanks in advance.Omar Andrés Rosada Gonzálezhttps://fr.mathworks.com/matlabcentral/profile/authors/14131479tag:fr.mathworks.com,2005:Question/5757732020-08-05T20:27:47Z2020-08-05T22:35:19ZMatlab livescript copy and pasteI want to move, let me say, 200 lines of code in Livescript (in one section) to the end of the script (say). Is there any way better than copy and paste? Is it possible to choose a "section" and copy and paste? alpedhuezhttps://fr.mathworks.com/matlabcentral/profile/authors/10930090tag:fr.mathworks.com,2005:Question/1283812014-05-05T19:49:31Z2020-08-05T22:33:33ZHow to calculate mean wind directionHello!
I need help figuring out how to calculate mean wind direction when my data is in degrees (0-360). I just realized my current program does not take into account that the data is circular, and the mean of 355 and 5 will be 180, instead of 0. Any help is greatly appreciated! I am a beginner when it comes to MATLAB programmingJenna Mariehttps://fr.mathworks.com/matlabcentral/profile/authors/5211601tag:fr.mathworks.com,2005:Question/5755692020-08-05T14:30:18Z2020-08-05T22:32:18ZHi, I have a dynamic plot. That shows me the data of a sensor of a robot. I need to have an interface that with 2 buttons allows me to plot the next data or the previous data.Hi, i have a dynamic plot like this:
clear all
clc
close all
table = readtable('laser_data.csv');
array = table2array(table);
h=animatedline('Marker','.','MarkerSize',12,'LineStyle', 'none','color','g');
xlabel('Distancia en el eje X')
ylabel('Distancia en el eje Y')
title('Obstáculos')
for i = 1:length(array)
%LEFT
for k = 2:2:30
x = -0.018+array(i,k);
y = 0.0899+array(i,k+1);
addpoints(h,x,y)
drawnow limitrate
%pause(0.00001)
end
%FRONT
for k = 32:2:60
x = 0.05620-array(i,k+1);
y = array(i,k);
addpoints(h,x,y)
drawnow limitrate
%pause(0.00001)
end
%RIGHT
for k = 62:2:90
x = 0.018-array(i,k);
y = -0.0899-array(i,k+1);
addpoints(h,x,y)
drawnow limitrate
% pause(0.00001)
end
end
And i need to have a GUI that allows me to hit a "next" button or a "previous" button that changes the plot instantaneously. And if i press for example the first time, the program will plot the ( i=1, k=2 ) data. Thanks, and i hope you can help me there!Santiago Villamilhttps://fr.mathworks.com/matlabcentral/profile/authors/14261191tag:fr.mathworks.com,2005:Question/5758002020-08-05T21:56:15Z2020-08-05T22:31:06ZGraph two curves together (datetime format and double format)Hi, thank you so much for reading me, i am using matlab 2019a, and i have this problem, i want to graph a function of curvefitting with my original curve, but i can't for this error that appears (attach photo) , i want the two graphs together .......
thank you so much for your valious time
tEnersol=readtable('solar.xlsx','sheet','EneDics'); % read into a table object
tEnersol.Properties.VariableNames={'Rad','Dia'}; % assign variable names
% yr=2014; % need the proper year
tEnersol.Date=datetime(yr,1,tEnersol.Dia); % and create a date column
hB=plot(tEnersol.Date,tEnersol.Rad, '.r'); hold on % bar plot against actual date
hAx=gca; % get axes handle...
xlim([datetime(2014,1,1) datetime(2014,12,12)]) % set limit to cover the full year
hAx.XAxis.TickLabelFormat='MM'; % show day of MONTH
% xticklabels(cellstr(tEnersol.Date(xticks))) % use the date string as tick labels
hAx.XTickLabelRotation=45; % rotate so can have chance to read...
xlabel('Mes del año, TMYE'), ylabel('Irradiancia solar máxima [KWh/m^2]');
a1= 2329
b1= 0.6522
c1= 0.95
a2= 1519
b2= 0.7781
c2= -2.545
d = (1:1:365);
w = a1.*sin(b1.*d+c1) + a2.*sin(b2.*d+c2)
plot(d,w,'.-b'); hold off Ana Sophhttps://fr.mathworks.com/matlabcentral/profile/authors/17227402tag:fr.mathworks.com,2005:Question/5758032020-08-05T21:58:03Z2020-08-05T22:29:51ZWhy matlab scatter plot edges looks strange/old fashined?I am intersted to make a plot similor to:
Here is what matlab plots:
I changed the edge width and it became worse:
I tried plot as well. It looks the same. Any idea how can I make the edge line of the marker look similar to the first plot?
Zeynab Mousavikhamenehttps://fr.mathworks.com/matlabcentral/profile/authors/14179884tag:fr.mathworks.com,2005:Question/5755632020-08-05T14:20:26Z2020-08-05T22:27:02ZWhy is it that the breakpoint does not work?I define some function. I set a breakpoint in the first line after the function definition statement. But when I run the program the program does not stop at the breakpoint. Why? alpedhuezhttps://fr.mathworks.com/matlabcentral/profile/authors/10930090tag:fr.mathworks.com,2005:Question/5751252020-08-04T17:44:31Z2020-08-05T22:20:53Zfill rectangles with colors hello ..
i used this instraction to plot rectangles with defrent colors ..i need help to fill those rectangles with colors .>>
thanks for hellllp :)
.plot([posx posx+Element(i).W posx+Element(i).W posx posx],...
[posy posy posy+Element(i).H posy+Element(i).H posy],...
'-','color',cl(i,:))
ahmed noorihttps://fr.mathworks.com/matlabcentral/profile/authors/14206134tag:fr.mathworks.com,2005:Question/5757702020-08-05T20:27:05Z2020-08-05T22:14:47ZHow to associate a rectangle with a struct?Hi there Community,
I have the folllowing image and the antenna:
[Horizontal,Vertical,Optional] = msiread(strcat(pathName,fileName));
How can I associate a rectangle to an antenna?
I made the rectangle using:
rectangle('Position', [(x - handles.Rwidth/2) (y - handles.Rwidth/2)...
handles.Rwidth handles.Rheight], 'FaceColor', 'g','LineStyle', 'none');
Is it possible to affect the rectangule with the struct (antenna)?Oliver Lestrangehttps://fr.mathworks.com/matlabcentral/profile/authors/19092523tag:fr.mathworks.com,2005:Question/5751522020-08-04T18:40:24Z2020-08-05T22:13:34ZI need help solving a system of differential equations. The equations are given below, in matrix form. The problem that I'm having is regarding the fact that I have time dependant elements in the matrices.Jelena Kresojahttps://fr.mathworks.com/matlabcentral/profile/authors/12912861tag:fr.mathworks.com,2005:Question/5749422020-08-04T12:46:28Z2020-08-05T22:13:14ZI need help with parpool and optimizing recources for image reconstruction, running matlab with batch scriptIm running an image reconstruction (1798 head volumes) script on a computation cluster
These are my recources
Nodes: 1
Mem per core: 43 GB
Cores per node: 24
Mem tot: 1024 GB
The reconstruction script reconstructs each full head volume (total 1798 head volumes) in the for loop for k=1:length(tframes), tframes=1798:
Now, my idea is to use parpool to parallelize the for loop. When using parpool one needs to specify the number of workers. This number should match the number of CPUs requested.
IN the computation cluster I use recources are requested as follows:
#SBATCH -p hugemem % name of the partition
#SBATCH -t 072:00:00 &time
#SBATCH --nodes=1 %nodes
#SBATCH --mem-per-cpu= 43G
#SBATCH --ntasks= 24
#SBATCH --cpus-per-task= 1
My question, how should I use parpool to parallelize this task of reconstructing the 1798 head volumes? Or do you think in this case parfor would be better?
Pseudoscientisthttps://fr.mathworks.com/matlabcentral/profile/authors/7526856tag:fr.mathworks.com,2005:Question/5758092020-08-05T22:08:59Z2020-08-05T22:08:59ZInterpolating at vertices of a meshI have created a mesh using the initmesh in 2D, which gives the nodes (p), boundary (e) and triangular elements (t). I have a function/vector calculated at each triangular elements, I need to interpolate the function at the vertices of the mesh. How do I do it?Sanwar Ahmadhttps://fr.mathworks.com/matlabcentral/profile/authors/16136105tag:fr.mathworks.com,2005:Question/5757942020-08-05T21:43:00Z2020-08-05T22:07:20ZHow to edit colors for the line?
The legend line corlor is wrong. How do I change the black to green for the measured one?Yingyi Huanghttps://fr.mathworks.com/matlabcentral/profile/authors/18892023tag:fr.mathworks.com,2005:Question/5746902020-08-03T22:41:41Z2020-08-05T22:04:13Zmlx file in UbuntuI create a mlx file on Ubuntu and try to save it. Then it is saved actually as a folder with matlab, metadata, and _rels folders. Why? How can one deal with them? alpedhuezhttps://fr.mathworks.com/matlabcentral/profile/authors/10930090tag:fr.mathworks.com,2005:Question/5758062020-08-05T22:02:59Z2020-08-05T22:04:06Zthe variable appears to change size of every loop iteration?I tried to fix this problem but error message appear
In an assignment A(I) = B, the number of elements in B and I must be the same
What is wrong with this code?
D=zeros(4)
For i=1:4
D(i)=conv(D(i,:),[1 0])
End
msh jgtuhttps://fr.mathworks.com/matlabcentral/profile/authors/2340723tag:fr.mathworks.com,2005:Question/3322242017-03-27T23:58:02Z2020-08-05T22:00:08ZIs it possible to install matlab in a docker image?I wanted to install my matlab in a docker image. Is that possible?Brando Mirandahttps://fr.mathworks.com/matlabcentral/profile/authors/2706824tag:fr.mathworks.com,2005:Question/5749452020-08-04T12:54:07Z2020-08-05T21:56:46ZCluster profile validation stuckHello Matlab experts,
I have never used parallel computing in MATLAB but was trying to use these days. I can't make it work so far. When I try even parpool(1), it gets stuck in "Starting ...." for ever. I opened the Cluster Profile Manager and do the validation, it gets stuck in "Job test (createJob)". I am using the "local" cluster. Any advice what I need to do?
Thanks.
Regards,
TianxiangTianxiang Suhttps://fr.mathworks.com/matlabcentral/profile/authors/8412266tag:fr.mathworks.com,2005:Question/5757432020-08-05T19:37:19Z2020-08-05T21:56:40ZXMAX must be a floating point scalarclc,clear all,close all;
syms beta theta r ;
D = 10;
C = 10;
L1 = 4;
Ri = D/2 + L1;
Rbeta0 = Ri;
Rt0 = (2*L1*cos(theta) + sqrt((D^2) - (2*(L1^2)) + (2*(L1^2)*cos(2*theta))) )/2;
Rmaxtb0 = (Rt0*Rbeta0)/Ri;
Rmaxtb00 = matlabFunction(Rmaxtb0)
Vmbeta0 = (2*(pi^2)*((D+(2*L1))^2)) / ((((2*L1*pi)+(pi*D))^2));
Vbeta0 = Vmbeta0 * (1 - ((r^2) / (Rmaxtb0^2))) * r;
Vbeta00 = matlabFunction(Vbeta0)
Wsigmat = integral2(Vbeta00,0,Rmaxtb00,0,2*pi,'AbsTol',1e-5, 'RelTol',1e-5)
I got the following error:
Error using integral2 (line 76)
XMAX must be a floating point scalar.
this is the integral:
any help?
(thanks in advance)Pooyan Jafarihttps://fr.mathworks.com/matlabcentral/profile/authors/16688140tag:fr.mathworks.com,2005:Question/5748612020-08-04T09:05:24Z2020-08-05T21:55:18ZQuestions on Parallel Computing Toolbox cluster validationHello Everyone
I am new to Parallel Computing Toolbox. Here I met a problem when I want to validate my local cluster. It can not pass the create job test.
Here is the error report.
Profile: local
Scheduler Type: Local
Stage: Cluster connection test (parcluster)
Status: Passed
Start Time: Tue Aug 04 04:53:32 EDT 2020
Finish Time: Tue Aug 04 04:53:33 EDT 2020
Running Duration: 0 min 1 sec
Description:
Error Report:
Command Line Output:
Debug Log:
Stage: Job test (createJob)
Status: Stopped
Start Time: Tue Aug 04 04:53:33 EDT 2020
Finish Time:
Running Duration:
Description: Validation interrupted during execution.
Error Report:
Command Line Output:
Debug Log:
I have tried method in this and none of them work. I am wondering if anyone have met this problem before.
Dian Jinhttps://fr.mathworks.com/matlabcentral/profile/authors/14970863tag:fr.mathworks.com,2005:Question/5100492020-03-10T10:32:40Z2020-08-05T21:45:24ZWhich formula fits better for this Linear Mixed-Effects Model?I am currently analyzing a dataset that contains a list of flight simulator tests performed by different pilots. I want to analyze if a certain flight parameter (i.e. amount of input errors during flight, lateral deviation to ideal path, etc.) are affected by the categorical variables in the following list:
Experimental Campaign: the pilots flew the same flights but in different places (and environmental conditions, such as lack of oxygen, isolation, etc). 5 different campaigns were done. A performance difference is likely to appear depending on the campaigns.
Group: in each campaign, the pilots were divided in two groups: Frequend and infrequent flyers. A performance difference is expected between both groups.
Session: During each campaign, the same amount of flights were performed, each month for FF pilots, or every three months for IF Pilots. In total, 10 sessions were made. A variation of performance might happen throughout the experiment, also affected by Group and Campaign.
Flight Scenario: three different flight scenarios were flown, which required different skill levels. The performance is also expected to vary between type of scenario.
Additionally, an extra list of categorical variables could be considered (Gender, Age, Background, etc.).
Could you please tell me which LME Model formula would you better implement in order to understand the dataset presented? And if you wish, how would you better plot the results of such an analysis?
Thank you!!Miquel Bosch Bruguerahttps://fr.mathworks.com/matlabcentral/profile/authors/9525291tag:fr.mathworks.com,2005:Question/5751072020-08-04T17:01:06Z2020-08-05T21:44:23ZApp Slow With UIAxesHi. I'm creating apps on app designer which use components such as sliders to control a plot. When plotting on a UIAxes, there is significant delay. However, when having the app plot on a separate figure, there is no delay. Does anyone know the reason for this and if there's a way to plot on the UIAxes without the delay? Thanks.
I'm going to use an app modelling a cylinder removing a lot of the additional unnecessary stuff, so the type of problem is as clear as possible. The plot consists of surf, patch, and plot3. For all apps, the goal is not plotting data per say, but rather creating shapes, often in 3 dimensions. Therefore, the data is generally arrays of type double which don't generally get over 100 elements.
I'm using MATLAB R2020a.
These are the two methods:
I drag and drop a UIAxes on to the app and plot on that axis. This takes about 3 seconds to update the plot each time I move the slider. This is a screenshot of the setup:
I create a separate regular figure (not uifigure) and plot it on that. This has almost no delay:
This is the code used to create the separate figure and have them aligned neatly (I don't think it's that important but it clarifies what I'm doing):
global ax %needed so it can be accessed through component callbacks
divide=.2;%the fraction of the screen filled by the app
set(0,'units','pixels')
pixels=get(0,'screensize');
app.UIFigure.Position=[0,0,divide*pixels(3),pixels(4)];
fig=figure; %new figure
fig.Position=[divide*pixels(3),0,(1-divide)*pixels(3),pixels(4)];
ax=axes(fig); %axis it will be plotted on
Here is the code which I used (I removed much of the code used in the original app to simplify things) (the code is based off of Clay M. Thompson's cylinder function, and I kept the copyright text in the code):
function torsion(ax,ax2,M,G,L,r,display_in)
% Clay M. Thompson 4-24-91, CBM 8-21-92.
% Copyright 1984-2002 The MathWorks, Inc.
cla(ax)
% engineering equations:
J=1/4*r^4;
phi=M*L/(J*G);
% set up cylinder:
n = 50;
r = [r r]';
r = r(:); % Make sure r is a vector.
m = length(r); if m==1, r = [r;r]; m = 2; end
theta = (0:n)/n*2*pi;
sintheta = sin(theta); sintheta(n+1) = 0;
x = r * cos(theta);
y = r * sintheta;
z = (0:m-1)'/(m-1) *L* ones(1,n+1);
hold(ax,'on')
% plot cylinder
surf(ax,x,y,z,'EdgeColor','none','FaceAlpha',1)
patch(ax,x(1,:),y(1,:),z(1,:),[.25 0 .7])
patch(ax,x(1,:),y(1,:),z(2,:),[.25 0 .7])
%plot helices
z_vals=linspace(0,L,n*L/(2*pi*r(1)));
for i=0:n-1
angle0=i*(2*pi)/n;
anglef=angle0+phi;
theta_part=linspace(angle0,anglef,length(z_vals));
x_part=(r*1.01)*cos(theta_part);
y_part=(r*1.01)*sin(theta_part);
z_vals=linspace(0,L,length(x_part));
plot3(ax,x_part,y_part,z_vals,'k','LineWidth',.5)
end
% plot circles
for i=z_vals
plot3(ax,x,y,i*ones(1,n+1),'k','LineWidth',.5)
end
end
Ephraim Bryskihttps://fr.mathworks.com/matlabcentral/profile/authors/14049778tag:fr.mathworks.com,2005:Question/5756922020-08-05T17:40:30Z2020-08-05T21:39:53Zfminbnd got stock in local minimum: can global search deal with the problem defined by cases?I plot the value of a function over the possible values and also run fminbnd. I find out that fminbud got stuck in a local minimum. As a next step I would consider global optimization toolbox. Can they handle function defined by cases? alpedhuezhttps://fr.mathworks.com/matlabcentral/profile/authors/10930090tag:fr.mathworks.com,2005:Question/5757582020-08-05T20:06:47Z2020-08-05T21:39:19Zscatter plot with color dependent on variable. I need to plot a scatter graph, where the color goes from red to blue gradually and depends on the value of variable s (polarization value). s is calculated in excel and goes from -1 to 1. I am not sure how to achieve the above.
I am trying the following code: attached.
Any help is appreciated.
David Levyhttps://fr.mathworks.com/matlabcentral/profile/authors/4053704tag:fr.mathworks.com,2005:Question/5711442020-07-27T12:09:58Z2020-08-05T21:38:33Zhow to access coolprop or EES in online matlab is there any way to access coolprop or EES in online matlab for find out thermophysical properties of fluids.
i want to calculate n-pentane properties .RAM KUMAR PRAJAPATIhttps://fr.mathworks.com/matlabcentral/profile/authors/18929226tag:fr.mathworks.com,2005:Question/5757882020-08-05T21:18:04Z2020-08-05T21:34:19ZStehfest algorithm for a problem of inverse Laplace with Bessel functionI am trying to compare the following inverse Laplace function. The numerical approximation of the function is know but somehow I could not get the correct result' not even close.
The function is as follow
where and are constant numbers. And, is the modified Bessel's function of the second kind of order .
In this case, I have assumed the following:
a = 0.127;
r = 0:0.1:2;
co = 9.54e-7;
Tw = 400;
t = 864;
For the small value of and , the function can be approximated by
in which is an error function.
(this formula is taken from Eq. 40 in here: Wang, Y., and Papamichos, E. (1994), Conductive heat flow and thermally induced fluid flow around a well bore in a poroelastic medium, Water Resour. Res., 30( 12), 3375– 3384, doi:10.1029/94WR01774.)
To approximate this function, I have use the following Matlab code from https://uk.mathworks.com/matlabcentral/fileexchange/9987-gaver-stehfest-algorithm-for-inverse-laplace-transform
that uses Stehfest algorithm.
But somehow I could not get the answer consistent with the analytical approximation. Can anyone help me?
clear all; close all
global r co Tw a
a = 0.127;
r = 0:0.1:2;
co = 9.54e-7;
Tw = 400;
t = 864;
X = (r-a)./(2*sqrt(co*t));
I = erf(X);
Trt = Tw*sqrt((a./r)).*I;
plot(r,Trt,'bo-');hold on
% using stehfest algoritm
ilt=gavsteh('fun1',t,16);
plot(r,ilt,'rs-But')
function f = fun1(p)
global r co Tw a
f = Tw.*(1/p).*((besselk(0,sqrt(p/co).*r))./(besselk(0,sqrt(p/co).*a)));
end
function ilt=gavsteh(funname,t,L)
nn2 = L/2;
nn21= nn2+1;
for n = 1:L
z = 0.0;
for k = floor( ( n + 1 ) / 2 ):min(n,nn2)
z = z + ((k^nn2)*factorial(2*k))/ ...
(factorial(nn2-k)*factorial(k)*factorial(k-1)* ...
factorial(n-k)*factorial(2*k - n));
end
v(n)=(-1)^(n+nn2)*z;
end
sum = 0.0;
ln2_on_t = log(2.0) / t;
for n = 1:L
p = n * ln2_on_t;
sum = sum + v(n) * feval(funname,p);
end
ilt = sum * ln2_on_t;
endBeeTiawhttps://fr.mathworks.com/matlabcentral/profile/authors/318942tag:fr.mathworks.com,2005:Question/5743572020-08-03T10:11:37Z2020-08-05T21:32:38ZMATLAB coder GUI / CLI shows cryptic errors: libmwboost / CUDA_CODEGENHi, I hit a number of snags when using MATLAB coder. I'm using R2020a on Ubuntu 18.04 on an XPS 15 9570.
Issue no.1 (GUI): When I run the GUI, I am stopped at the automatically define input types step by the message
"Invalid MEX-file '/path/on/my/machine' : libmwboost_system.so.1.65.1: cannot open shared object file: No such file or directory.
However...
>> !locate libmwboost_system
/usr/local/MATLAB/R2020a/bin/glnxa64/libmwboost_system.so.1.70.0
Why doesn't MATLAB detect and use the latest version of this .so? How to fix this problem?
Issue no.2 (CLI): Raw C code is better than nothing. so I ran the command below and hit another snag
>> codegen -c foo
CRL: "CUDA_CODEGEN" cannot be found in the registry.
Use help codegen for more information on using this command.
Error using codegen
Googling for CUDA_CODEGEN doesn't even give relevant results. Before diving into debugging GPU issues, I need to emphasize that CUDA code generation is the absolute least of my concern. If there is a way to make Coder ignore CUDA and move on, I'd go with that.
I'm totally stalled now and I greatly appreciate any answer.
Both issues manifest with the simplest toy function like
function y = foo(x)
y = x;
end
Hei Shing Helson Gohttps://fr.mathworks.com/matlabcentral/profile/authors/19008898tag:fr.mathworks.com,2005:Question/5554632020-06-26T20:24:15Z2020-08-05T21:30:59ZHow to fitline on my binary image and find distanceHello,
I have a question about my image processing problem. I have convert the image into binary and now i would like to use fitline on my image. Basically want to smooth the line with the curve. I am a beginner for MATLAB software. Please help me to find the solution. Also i want to find distance of one thin line to thick line (top to bottom).
I am attachng my picture as png. Also my code is there.Prashanthttps://fr.mathworks.com/matlabcentral/profile/authors/12182670tag:fr.mathworks.com,2005:Question/3663742017-11-11T00:10:56Z2020-08-05T21:30:32ZProblem computing inverse Laplace transform of the Bessel functionI am trying to evaluate the inverse Laplace transform of a function that includes the modified Bessel function of the second kind, i.e., my function is f_s = sqrt(a*s)*besselk(1,2*sqrt(a*s)), where a is a constant (say a = 0.5) and 's' is defined as a symbol. To evaluate the inverse Laplace transform of this function, I used the built-in Matlab function 'ilaplace' as transV = ilaplace(f_s,s,t), where I want to evaluate my function at 't' = 2. However, the problem I am getting is that the inverse transformed expression transV still contains 's' variable, which I supposed to transform to 't' after the inverse Laplace transform.
Can anyone help me with what is the problem with this approach? I checked the Matlab documentation and still couldn't figure out the solution. I already tried using 'vpa' function as it was suggested in one of the Matlab forums, but that didn't help to get rid of 's'. I am stuck with this and would really appreciate any help on it.
My code is
a = 0.5; t = 2;
syms s;
f_s = 1/s*sqrt(a*s)*besselk(1,2*sqrt(a*s));
transV = ilaplace(f_s,t); % or transV = vpa(ilaplace(f_s,t));
With this, the final result transV still has an expression which is a function of 's' although it should be transformed after ilaplace.Kevin Bhttps://fr.mathworks.com/matlabcentral/profile/authors/11474116tag:fr.mathworks.com,2005:Question/5749122020-08-04T11:45:25Z2020-08-05T21:28:33ZHow to improve performances in solving ODEs?I'm studying a quarter car model and my aim is to introduce some of the nonlinearities typical of a real suspension, because I want to realize a model which is closer to reality than the classical one. What I've done so far is to introduce an elastic element composed by a spring and two bump stops acting in parallel and which is described by two polynomials in jounce and rebound. Then I used the same method to describe an asymmetric damper and in the end I defined a condition which introduce the possibility for the unsprung mass to lose contact with the ground. The result is the code written
function f = solve(tspan,y)
load Data M m kt
load MollaNonLineare kst1 kst2 kst3 kst4 kst5 kst6 kst7 ksh1 ksh2 ksh3 ksh4 ksh5 ksh6 ksh7
load CoeffAmmo csh1 csh2 csh3 csh4 csh5 csh6 csh7 cst1 cst2 cst3 cst4 cst5 cst6 cst7
cc = 0;
g = 9.81;
h = 0.01;
f = zeros(4,1);
f(1) = y(2);
if (y(1) - y(3))>0 && (y(2) - y(4))>=0
f(2) = (- csh7*(y(2) - y(4)) - csh6*(y(2) - y(4))^2 - csh5*(y(2) - y(4))^3 - csh4*(y(2) - y(4))^4 - csh3*(y(2) - y(4))^5 - csh2*(y(2) - y(4))^6 - csh1*(y(2) - y(4))^7 - cc*sign(y(2) - y(4)) - kst7*(y(1) - y(3)) - kst6*(y(1) - y(3))^2 - kst5*(y(1) - y(3))^3 - kst4*(y(1) - y(3))^4 - kst3*(y(1) - y(3))^5 - kst2*(y(1) - y(3))^6 - kst1*(y(1) - y(3))^7)/M;
elseif (y(1) - y(3))>0 && (y(2) - y(4))<0
f(2) = (- cst7*(y(2) - y(4)) - cst6*(y(2) - y(4))^2 - cst5*(y(2) - y(4))^3 - cst4*(y(2) - y(4))^4 - cst3*(y(2) - y(4))^5 - cst2*(y(2) - y(4))^6 - cst1*(y(2) - y(4))^7 - cc*sign(y(2) - y(4)) - kst7*(y(1) - y(3)) - kst6*(y(1) - y(3))^2 - kst5*(y(1) - y(3))^3 - kst4*(y(1) - y(3))^4 - kst3*(y(1) - y(3))^5 - kst2*(y(1) - y(3))^6 - kst1*(y(1) - y(3))^7)/M;
elseif (y(1) - y(3))<0 && (y(2) - y(4))>=0
f(2) = (- csh7*(y(2) - y(4)) - csh6*(y(2) - y(4))^2 - csh5*(y(2) - y(4))^3 - csh4*(y(2) - y(4))^4 - csh3*(y(2) - y(4))^5 - csh2*(y(2) - y(4))^6 - csh1*(y(2) - y(4))^7 - cc*sign(y(2) - y(4)) - ksh7*(y(1) - y(3)) - ksh6*(y(1) - y(3))^2 - ksh5*(y(1) - y(3))^3 - ksh4*(y(1) - y(3))^4 - ksh3*(y(1) - y(3))^5 - ksh2*(y(1) - y(3))^6 - ksh1*(y(1) - y(3))^7)/M;
else
f(2) = (- cst7*(y(2) - y(4)) - cst6*(y(2) - y(4))^2 - cst5*(y(2) - y(4))^3 - cst4*(y(2) - y(4))^4 - cst3*(y(2) - y(4))^5 - cst2*(y(2) - y(4))^6 - cst1*(y(2) - y(4))^7 - cc*sign(y(2) - y(4)) - ksh7*(y(1) - y(3)) - ksh6*(y(1) - y(3))^2 - ksh5*(y(1) - y(3))^3 - ksh4*(y(1) - y(3))^4 - ksh3*(y(1) - y(3))^5 - ksh2*(y(1) - y(3))^6 - ksh1*(y(1) - y(3))^7)/M;
end
f(3) = y(4);
if tspan<1 && (y(1) - y(3))>0 && (y(2) - y(4))>=0
f(4) = (csh7*(y(2) - y(4)) + csh6*(y(2) - y(4))^2 + csh5*(y(2) - y(4))^3 + csh4*(y(2) - y(4))^4 + csh3*(y(2) - y(4))^5 + csh2*(y(2) - y(4))^6 + csh1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + kst7*(y(1) - y(3)) + kst6*(y(1) - y(3))^2 + kst5*(y(1) - y(3))^3 + kst4*(y(1) - y(3))^4 + kst3*(y(1) - y(3))^5 + kst2*(y(1) - y(3))^6 + kst1*(y(1) - y(3))^7 - kt*y(3))/m;
elseif tspan<1 && (y(1) - y(3))>0 && (y(2) - y(4))<0
f(4) = (cst7*(y(2) - y(4)) + cst6*(y(2) - y(4))^2 + cst5*(y(2) - y(4))^3 + cst4*(y(2) - y(4))^4 + cst3*(y(2) - y(4))^5 + cst2*(y(2) - y(4))^6 + cst1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + kst7*(y(1) - y(3)) + kst6*(y(1) - y(3))^2 + kst5*(y(1) - y(3))^3 + kst4*(y(1) - y(3))^4 + kst3*(y(1) - y(3))^5 + kst2*(y(1) - y(3))^6 + kst1*(y(1) - y(3))^7 - kt*y(3))/m;
elseif tspan<1 && (y(1) - y(3))<0 && (y(2) - y(4))>=0
f(4) = (csh7*(y(2) - y(4)) + csh6*(y(2) - y(4))^2 + csh5*(y(2) - y(4))^3 + csh4*(y(2) - y(4))^4 + csh3*(y(2) - y(4))^5 + csh2*(y(2) - y(4))^6 + csh1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + ksh7*(y(1) - y(3)) + ksh6*(y(1) - y(3))^2 + ksh5*(y(1) - y(3))^3 + ksh4*(y(1) - y(3))^4 + ksh3*(y(1) - y(3))^5 + ksh2*(y(1) - y(3))^6 + ksh1*(y(1) - y(3))^7 - kt*y(3))/m;
elseif tspan<1 && (y(1) - y(3))<0 && (y(2) - y(4))<0
f(4) = (cst7*(y(2) - y(4)) + cst6*(y(2) - y(4))^2 + cst5*(y(2) - y(4))^3 + cst4*(y(2) - y(4))^4 + cst3*(y(2) - y(4))^5 + cst2*(y(2) - y(4))^6 + cst1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + ksh7*(y(1) - y(3)) + ksh6*(y(1) - y(3))^2 + ksh5*(y(1) - y(3))^3 + ksh4*(y(1) - y(3))^4 + ksh3*(y(1) - y(3))^5 + ksh2*(y(1) - y(3))^6 + ksh1*(y(1) - y(3))^7 - kt*y(3))/m;
elseif tspan>=1 && y(3) - h < (M+m)*g/kt && (y(1) - y(3))>0 && (y(2) - y(4))>=0
f(4) = (kt*h + csh7*(y(2) - y(4)) + csh6*(y(2) - y(4))^2 + csh5*(y(2) - y(4))^3 + csh4*(y(2) - y(4))^4 + csh3*(y(2) - y(4))^5 + csh2*(y(2) - y(4))^6 + csh1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + kst7*(y(1) - y(3)) + kst6*(y(1) - y(3))^2 + kst5*(y(1) - y(3))^3 + kst4*(y(1) - y(3))^4 + kst3*(y(1) - y(3))^5 + kst2*(y(1) - y(3))^6 + kst1*(y(1) - y(3))^7 - kt*y(3))/m;
elseif tspan>=1 && y(3) - h < (M+m)*g/kt && (y(1) - y(3))>0 && (y(2) - y(4))<0
f(4) = (kt*h + cst7*(y(2) - y(4)) + cst6*(y(2) - y(4))^2 + cst5*(y(2) - y(4))^3 + cst4*(y(2) - y(4))^4 + cst3*(y(2) - y(4))^5 + cst2*(y(2) - y(4))^6 + cst1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + kst7*(y(1) - y(3)) + kst6*(y(1) - y(3))^2 + kst5*(y(1) - y(3))^3 + kst4*(y(1) - y(3))^4 + kst3*(y(1) - y(3))^5 + kst2*(y(1) - y(3))^6 + kst1*(y(1) - y(3))^7 - kt*y(3))/m;
elseif tspan>=1 && y(3) - h < (M+m)*g/kt && (y(1) - y(3))<0 && (y(2) - y(4))>=0
f(4) = (kt*h + csh7*(y(2) - y(4)) + csh6*(y(2) - y(4))^2 + csh5*(y(2) - y(4))^3 + csh4*(y(2) - y(4))^4 + csh3*(y(2) - y(4))^5 + csh2*(y(2) - y(4))^6 + csh1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + ksh7*(y(1) - y(3)) + ksh6*(y(1) - y(3))^2 + ksh5*(y(1) - y(3))^3 + ksh4*(y(1) - y(3))^4 + ksh3*(y(1) - y(3))^5 + ksh2*(y(1) - y(3))^6 + ksh1*(y(1) - y(3))^7 - kt*y(3))/m;
elseif tspan>=1 && y(3) - h < (M+m)*g/kt && (y(1) - y(3))<0 && (y(2) - y(4))<0
f(4) = (kt*h + cst7*(y(2) - y(4)) + cst6*(y(2) - y(4))^2 + cst5*(y(2) - y(4))^3 + cst4*(y(2) - y(4))^4 + cst3*(y(2) - y(4))^5 + cst2*(y(2) - y(4))^6 + cst1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + ksh7*(y(1) - y(3)) + ksh6*(y(1) - y(3))^2 + ksh5*(y(1) - y(3))^3 + ksh4*(y(1) - y(3))^4 + ksh3*(y(1) - y(3))^5 + ksh2*(y(1) - y(3))^6 + ksh1*(y(1) - y(3))^7 - kt*y(3))/m;
elseif tspan>=1 && y(3) - h > (M+m)*g/kt && (y(1) - y(3))>0 && (y(2) - y(4))>=0
f(4) = (csh7*(y(2) - y(4)) + csh6*(y(2) - y(4))^2 + csh5*(y(2) - y(4))^3 + csh4*(y(2) - y(4))^4 + csh3*(y(2) - y(4))^5 + csh2*(y(2) - y(4))^6 + csh1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + kst7*(y(1) - y(3)) + kst6*(y(1) - y(3))^2 + kst5*(y(1) - y(3))^3 + kst4*(y(1) - y(3))^4 + kst3*(y(1) - y(3))^5 + kst2*(y(1) - y(3))^6 + kst1*(y(1) - y(3))^7 - (M + m)*g)/m;
elseif tspan>=1 && y(3) - h > (M+m)*g/kt && (y(1) - y(3))>0 && (y(2) - y(4))<0
f(4) = (cst7*(y(2) - y(4)) + cst6*(y(2) - y(4))^2 + cst5*(y(2) - y(4))^3 + cst4*(y(2) - y(4))^4 + cst3*(y(2) - y(4))^5 + cst2*(y(2) - y(4))^6 + cst1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + kst7*(y(1) - y(3)) + kst6*(y(1) - y(3))^2 + kst5*(y(1) - y(3))^3 + kst4*(y(1) - y(3))^4 + kst3*(y(1) - y(3))^5 + kst2*(y(1) - y(3))^6 + kst1*(y(1) - y(3))^7 - (M + m)*g)/m;
elseif tspan>=1 && y(3) - h > (M+m)*g/kt && (y(1) - y(3))<0 && (y(2) - y(4))>=0
f(4) = (csh7*(y(2) - y(4)) + csh6*(y(2) - y(4))^2 + csh5*(y(2) - y(4))^3 + csh4*(y(2) - y(4))^4 + csh3*(y(2) - y(4))^5 + csh2*(y(2) - y(4))^6 + csh1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + ksh7*(y(1) - y(3)) + ksh6*(y(1) - y(3))^2 + ksh5*(y(1) - y(3))^3 + ksh4*(y(1) - y(3))^4 + ksh3*(y(1) - y(3))^5 + ksh2*(y(1) - y(3))^6 + ksh1*(y(1) - y(3))^7 + ksh1*(y(1) - y(3))^7 - (M + m)*g)/m;
else
f(4) = (cst7*(y(2) - y(4)) + cst6*(y(2) - y(4))^2 + cst5*(y(2) - y(4))^3 + cst4*(y(2) - y(4))^4 + cst3*(y(2) - y(4))^5 + cst2*(y(2) - y(4))^6 + cst1*(y(2) - y(4))^7 + cc*sign(y(2) - y(4)) + ksh7*(y(1) - y(3)) + ksh6*(y(1) - y(3))^2 + ksh5*(y(1) - y(3))^3 + ksh4*(y(1) - y(3))^4 + ksh3*(y(1) - y(3))^5 + ksh2*(y(1) - y(3))^6 + ksh1*(y(1) - y(3))^7 + ksh1*(y(1) - y(3))^7 - (M + m)*g)/m;
end
end
In the code M stands for the sprung mass, m stands for the unsprung mass while kt is the tire stifness. Kst and Ksh are the coefficents of the two polynomials describing the behaviour of the suspension spring while it's stretching or shortening and the same is for Csh and Cst, where C is the damping coefficient. The goal of the code is to represent the behaviour of the model when it hits a step, so the road profile is described as 0 while tspan<1 and it's 0.01 m for tspan>1.
Now I want to ask you two questions: first of all I'd like to know if my code could be written in a more efficient way, because I realized that the introduction of simple nonlinearities makes the code slower. So I want to ask you if writing only two general equations describing f(2) and f(4) and evaluating all the parameters just one time at the beginning of every iteration could speed up the running of the script. In this case the code will be like
function f = solve(tspan,y)
load Data M m kt
load MollaNonLineare kst1 kst2 kst3 kst4 kst5 kst6 kst7 ksh1 ksh2 ksh3 ksh4 ksh5 ksh6 ksh7
load CoeffAmmo csh1 csh2 csh3 csh4 csh5 csh6 csh7 cst1 cst2 cst3 cst4 cst5 cst6 cst7
cc = 0;
g = 9.81;
if tspan<1
h = 0;
else
h = 0.01;
end
if y(1) - y(3)<0
k1 = ksh1;
k2 = ksh2;
else
k1 = kst1;
k2 = kst2
end
end
I didn't write the entire code purposely, because I don't want this question to become unnecessarily long, but the idea is that expressed in the previous lines.
My second question is about the introduction of a force related to the presence of friction in the components. I introduced the friction in a simple Coulombian way, using a coefficient cc and describing the force as
F = cc*sign(y(2) - y(4))
The problem which arises at this point is that the code becomes really slow, and I can't understand if this it's somehow related to the use of the sign function.Paolo Alloisiohttps://fr.mathworks.com/matlabcentral/profile/authors/14998737tag:fr.mathworks.com,2005:Question/5757912020-08-05T21:24:53Z2020-08-05T21:24:53ZSimulink data play backI am reading complex data samples from a binary file and displaying them with the constellation diagram. Currently the data is displayed on the diagram all at once. How can I gradually playback the data at a desired rate for observation?Stevenhttps://fr.mathworks.com/matlabcentral/profile/authors/2250006tag:fr.mathworks.com,2005:Question/5749782020-08-04T14:12:58Z2020-08-05T21:24:09Z"unable to classify the variable in the body of the parfor-loop" I tried
X=ones(b*n,5)
parfor (a=1:n, 12)
Y=X((a-1)*b+1:1:a*b,3:4);
sorted=sort(Y(:));
Z=sorted(end-2);
X((a-1)*b+1:1:a*b,5)=Z;
end
and obtained
Error: Unable to classify the variable 'bidder_samples' in the body of the parfor-loop. For more information, see Parallel for Loops in MATLAB, "Solve Variable Classification Issues in parfor-Loops".
What would be the next step? alpedhuezhttps://fr.mathworks.com/matlabcentral/profile/authors/10930090tag:fr.mathworks.com,2005:Question/5751792020-08-04T19:44:50Z2020-08-05T21:20:38ZHow to change patternsearch options for paretosearch algorithm?I need to change the options for patternsearch like the 'MeshExpansionFactor' for the paretosearch algorithm. How can i acheive that using optimoptions.
My Code:
oldoptions = optimoptions('patternsearch', 'MeshExpansionFactor', 4.0)
options = optimoptions('paretosearch', 'ParetoSetSize', 500, oldoptions)
[x, fval, exitflag, output] = paretosearch(fun, nvars, [], [], Aeq, beq, lb, ub, [], options);
Error:
Error using optimoptions (line 108)
Invalid option name specified. Provide a character vector or scalar string (such as 'Display').
A list of options can be found on the PARETOSEARCH documentation page.
Error in optimizationn (line 19)
options = optimoptions('paretosearch', 'ParetoSetSize', 500, oldoptions)
Surya Saket Dasikahttps://fr.mathworks.com/matlabcentral/profile/authors/7791382tag:fr.mathworks.com,2005:Question/5757672020-08-05T20:22:43Z2020-08-05T21:09:41ZHow to identify the location of a cell that meets a specific quantity conditionHey Everyone!
Is anyone familiar with an in-built MATLAB command that can specify locations of where a certain conditions is met?
For Example:
I have a gradient intensity matrix that lists the intensity of each pixel in an image and I want to find the index locations [x,y] of all pixels with a value greater than a set threshold.
I know this can be done in a FOR loop but I was curious if there was an equivalent like how some other coding languages have.Michael Vanegashttps://fr.mathworks.com/matlabcentral/profile/authors/14029101tag:fr.mathworks.com,2005:Question/3588592017-09-28T16:06:22Z2020-08-05T21:06:56ZIndex for array max (or min) in Simulink without variable-size signal or MATLAB Function blockIn Simulink I have a signal that is a 1-D array. I need to get the index associated with the first maximum (or minimum) value in the array. In MATLAB, that's simply this:
>> [val,idx] = max([2 3 6 8 4 7 8 4 5 6])
val =
8
idx =
4
where |idx| is the item I'm looking for.
Trying to do that in Simulink seems to be much less straightforward. The MinMax block does not offer an option to output the index of the first maximum value.
Coupling a MinMax with a Find Nonzero Elements blocks as in the suggestion on <https://www.mathworks.com/matlabcentral/answers/342732 this page> does do the trick, but it comes with the problem that the output of the find block is a variable-sized signal. I don't want it to be a variable sized signal; I just want the first index.
One could also use a MATLAB Function block and use the MATLAB min or max function as above, but MATLAB Function blocks take obnoxiously long to compile and often generate code with a lot of gunky overhead.
Is there not a simple, clean, cheap way to get the first max index?Michaelhttps://fr.mathworks.com/matlabcentral/profile/authors/5063721tag:fr.mathworks.com,2005:Question/5757462020-08-05T19:45:11Z2020-08-05T21:05:07ZImwrite creates 8bit tif file despite 16bit inputI have several 16bit images in a 3D array A. I want to save those images as one tiff file. However when using imwrite the images are stored as 8bit file.
The code is:
imwrite(A(:,:,1),'folderpath/test123.tif');
for n = [2:1:amount_of_images]
imwrite(A(:,:,n),'folderpath/test123.tif','WriteMode','append');
end
In the target folder one 8bit tif file appears, which is copletly white since all values in the original image are above 2^8-1
In the "current folder section" on the left the tiff file is also declared as 8bit. Judging by the documentation imwrite should recognise the 16bit, right? What am I doing wrong?
P.S. I am using R2019bMalte Römer-Stummhttps://fr.mathworks.com/matlabcentral/profile/authors/19137048tag:fr.mathworks.com,2005:Question/5757552020-08-05T20:05:37Z2020-08-05T21:01:17ZI want to produce square wave without using square function, but this code it showing error, "illegal use of IF keyword". How to rectify it?t=-10:0.1:10;
a=1;
for i=1:2:201
{
if a==1
{
z(1,i)=0;
z(1,i+1)=0;
}
else
{
z(1,i)=1;
z(1,i+1)=1;
}
end
a=a*(-1);
}
end
plot(t,z)
Piyush Guptahttps://fr.mathworks.com/matlabcentral/profile/authors/17813589tag:fr.mathworks.com,2005:Question/5757522020-08-05T20:01:50Z2020-08-05T20:57:11Zfor loop, change matrix dimensionsI have a matrix (A) which is 2156x25 in dimension.
I want to find if there are more than one equal element in column 2 that in first column have the same values (=67). For these elements I want to keep the corresponding first row and sum to this row the numbers of the third and fourth column of all these elements. Then I want to delete from the matrix the elements of the rows with same elements in second and first column(except the first row).
I have a problem in my code: the message is: Index in position 1 exceeds array bounds (must not exceed 958).
Why? Is this Because the matrix dimension change? Could I do something?
% Input: A is a matrix which is 2156x25
for k = 1:size(A,1)
dop = find(A(k,2) == CAR_GEN(:,2));
if size(dop,1) > 1
ccc = find(A(dop,1) == 67);
if(size(ccc,1)) > 1
A(ccc(1),3) = sum(A(ccc,3));
A(ccc(1),4) = sum(A(ccc,4));
A(ccc(2:end),:)= [];
end
end
end
Giovanni Gardanhttps://fr.mathworks.com/matlabcentral/profile/authors/11357655tag:fr.mathworks.com,2005:Question/5066732020-02-20T18:32:52Z2020-08-05T20:56:43ZHow to plot a line with repeated values of x?I have collected spectral data from two instruments and stitched the spectra together (simple concatenation). I want to make a plot tht shows how the spectra have been stitched together.
Spectrum 1 ranges from 180-1050, and Spectrum2 ranges from 120-1200. When I plot them, the lines overlap because the x values are repeated in each range.
How can I make Spectrum2 plot after Spectrum1 on it's own x-values?
This is what I have written:
data = xlsread('_______','Load_LL','D1:SJE4');
x = data(1,:);
PC1 = data(2,:);
PC2 = data(3,:);
PC3 = data(4,:);
plot(x,PC1,'-k',...
'LineWidth',0.75);
ylim([-0.3 0.1])
ylabel('PC-1');
set(h1,'FontName','Times New Roman','FontSize',10);
set(h1,'xtick',[])
And I get this:
I want something that looks more like this:
I tried plotting each spectrum as a subplot, which got me closer to my goal, but the two spectra should not take up the same space on the x axis (Spectrum1 has farrrr more variables).
How can I plot each y value with it's associated x vlue without getting overlap between repeted x values?Erin Gibbonshttps://fr.mathworks.com/matlabcentral/profile/authors/15851216tag:fr.mathworks.com,2005:Question/5757852020-08-05T20:53:48Z2020-08-05T20:53:48ZMultiple objective functions with fgoalattainI have multiple objective functions F1(x), F2(x), F3(x), ... Fn(x) that I would like to use fgoalattain to optimize simultaneously.
I have tried putting the objective functions in a cell array function handle:
fun = cellstr(string);
fun = cellfun(@str2func, fun, 'UniformOutput', false);
'string' is a cell array of strings which corresponds to function names (m files).
Each objective function has an associated goal and weight, such that length(fun) == length(goal) == length(weight)
Then I tried to call fgoalattain:
[x,fval] = fgoalattain(@(x)fun(x,par1, par2, par3, par4),x0,goal,weight)
However I get the following error:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Would anyone be able to help me with this optimization problem?
ThanksJimmy Zhanhttps://fr.mathworks.com/matlabcentral/profile/authors/10596043tag:fr.mathworks.com,2005:Question/5757612020-08-05T20:14:07Z2020-08-05T20:48:42ZHow do I read begin to read data after a string?In a txt file, I want to collect fcz data after "Concrete Stresses", how do I also Import the txt file to do so appropriately.
CONCRETE STRESSES
*****************
ELMT fcx fcy fcz Vcxy Vcyz Vcxz
(MPa) (MPa) (MPa) (MPa) (MPa) (MPa)
1 0.000 0.000 0.000 0.000 0.000 0.000
2 0.000 0.000 0.000 0.000 0.000 0.000
3 0.000 0.000 0.000 0.000 0.000 0.000
4 0.000 0.000 0.000 0.000 0.000 0.000
5 0.000 0.000 0.000 0.000 0.000 0.000
Desmond Hutchinsonhttps://fr.mathworks.com/matlabcentral/profile/authors/13492788tag:fr.mathworks.com,2005:Question/5755512020-08-05T14:02:51Z2020-08-05T20:41:32ZHow to parse text to numbers?Hi
I have text cell str looking like this? Is there a way to use regexp to convert this matrix?
ttxt = {'No info','1-50.00000','3-100.000','2-2.0000','Free & Unlimited', '1-100.0000;1-0.0000','1-25.000;1-50.000'}';
ttxt =
{'No info' }
{'1-50.00000' }; % one with 50%
{'3-100.000' } % three with 100% each
{'2-2.0000' } % two with 2% each
{'Free & Unlimited' } % three with 0%
{'1-100.0000;1-0.0000'} % two with first one 100% and 2nd one is 0%
{'1-25.000;1-50.000' } % two with first one 25% and 2nd one 50%
The rules are basically:
when the text is 'No info', it means there are no info, so it returns [0 0 0 0]
When the text is 'Free & Unlimited', it returns [3 0 0 0]
For other cases, there are 2 patterns:
first number > 1: 3-100... or 2-2.00, the first number tells number of repeated %. in this case there are 3 100% and 2 2%, respectively. So it should be [3 1 1 1] and [2 0.02 0.02 0]
multiple cell with ';' {'1-25.00;1-50.00'}; this means there are 2 data with first one is 25%, and 2nd one is 50%, so it should return [2 0.25 0.50 0.0]
want the output matrix to be
tdata = [0 0 0 0;
1 0.5 0 0;
3 1 1 1;
2 0.02 0.02 0;
3 0 0 0;
2 1 0 0;
2 0.25 0.5 0];Pete shererhttps://fr.mathworks.com/matlabcentral/profile/authors/1076536tag:fr.mathworks.com,2005:Question/5757792020-08-05T20:41:27Z2020-08-05T20:41:27ZFreeverbReverberator example Plugin errorHi
I´m trying to use the FreeverbReverberator as part of a more complex plugin. When I test it through audioTestBench as MatlabCode everything ok, but when I try to validate it for plugin creation, the following error appears:
"Unable to perform assignment because the left and right sides have a different number of elements.
Error in audioexample.FreeverbReverberator/parallelComb (line 261)
in(1:end) = sum(drySignal,2); "
Debugging the FreeverbReverberator code, I could verify that this missmatch in number of elements happens after the 1st cycle. So I have two questions:
1) Why this doesn´t happen when running as .m?
2) Is there any way to fix it for plugin creation porpouse?
If someone can shed light on this, I´d appretiatted.
Thanks
Pablo
PS: Follows the simple code, just in case you want to reproduce the issue described above. Bear in mind the error is refered to FreeverbReverberator code.
classdef Freeverb < audioPlugin
properties
RoomSize=0.6
WetDryMix = 1;
end
properties (Access = private)
preverb
end
properties (Constant)
PluginInterface = audioPluginInterface('PluginName','Ambience Creator','VendorName','Orion',......
audioPluginParameter('RoomSize',...
'DisplayName','',...
'Mapping',{'lin',0,1},...
'Label','m',...
'Style', 'hslider'),...
audioPluginParameter('WetDryMix',...
'DisplayName','',...
'Mapping',{'lin',0,1},...
'Label','m',...
'Style', 'hslider'));
end
methods
function plugin=Freeverb
plugin.preverb=audioexample.FreeverbReverberator;
end
function out = process(plugin, in)
outrev=plugin.preverb(in);
out=outrev;
end
%%
function set.RoomSize(plugin, val)
plugin.RoomSize = val;
calculatesize(plugin)
end
function set.WetDryMix(plugin, val)
plugin.WetDryMix = val;
calculatesize(plugin)
end
function calculatesize(plugin)
plugin.preverb.RoomSize=plugin.RoomSize;
plugin.preverb.WetDryMix=plugin.WetDryMix;
end
%%
function reset(plugin)
reset(plugin.preverb);
end
end
endPablo Panittahttps://fr.mathworks.com/matlabcentral/profile/authors/10018017tag:fr.mathworks.com,2005:Question/5757282020-08-05T18:57:51Z2020-08-05T20:38:59ZHow to read multiple text files and plot data?I have 6-7 different log files and I need to plot the data on a graph. Here is my code for retriving data from a single file and plotting it.
fid = fopen('North.txt');
C = textscan(fid, '%s');
endc = length(C{1});
posx = [str2double(C{1}{1})];
index = 1;
for v=13:12:endc
index = index + 1;
posx(index) = str2double(C{1}{v});
end
posy = [str2double(C{1}{2})];
index = 1;
for v=14:12:endc
index = index + 1;
posy(index) = str2double(C{1}{v});
end
posz = [str2double(C{1}{3})];
index = 1;
for v=15:12:endc
index = index + 1;
posz(index) = str2double(C{1}{v});
end
rotx = [str2double(C{1}{4})];
index = 1;
for v=16:12:endc
index = index + 1;
rotx(index) = str2double(C{1}{v});
end
roty = [str2double(C{1}{5})];
index = 1;
for v=17:12:endc
index = index + 1;
roty(index) = str2double(C{1}{v});
end
rotz = [str2double(C{1}{6})];
index = 1;
for v=18:12:endc
index = index + 1;
rotz(index) = str2double(C{1}{v});
end
eulx = [str2double(C{1}{7})];
index = 1;
for v=19:12:endc
index = index + 1;
eulx(index) = str2double(C{1}{v});
end
euly = [str2double(C{1}{8})];
index = 1;
for v=20:12:endc
index = index + 1;
euly(index) = str2double(C{1}{v});
end
eulz = [str2double(C{1}{9})];
index = 1;
for v=21:12:endc
index = index + 1;
eulz(index) = str2double(C{1}{v});
end
objx = [str2double(C{1}{10})];
index = 1;
for v=22:12:endc
index = index + 1;
objx(index) = str2double(C{1}{v});
end
objy = [str2double(C{1}{11})];
index = 1;
for v=23:12:endc
index = index + 1;
objy(index) = str2double(C{1}{v});
end
objz = [str2double(C{1}{12})];
index = 1;
for v=24:12:endc
index = index + 1;
objz(index) = str2double(C{1}{v});
end
figure(1);
plot3(posx, posy, posz);
figure(2);
plot3(rotx, roty, rotz);
figure(3);
plot3(eulx, euly, eulz);
figure(4);
plot3(objx, objy, objz);
Now What I want to do is read data from 5 other files(which have similar file structure as the first one) and plot the data in graphs. How do I read multiple files and plot the data?
Radhika Kulkarnihttps://fr.mathworks.com/matlabcentral/profile/authors/17819126tag:fr.mathworks.com,2005:Question/5757762020-08-05T20:31:29Z2020-08-05T20:31:29ZAccess Apache Hive using ODBC driverIs it possible to send SQL query to Apache Hive through ODBC and get the result in Matlab workspace? In Database toolbox, all examples are RDBMS,not Hive in HDFS.
Thank you for your help in advance.Harry Chohttps://fr.mathworks.com/matlabcentral/profile/authors/4246294