https://ww2.mathworks.cn/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-03-31T16:28:09Ztag:ww2.mathworks.cn,2005:Question/5143532020-03-31T16:28:09Z2020-03-31T16:28:09ZUpdating Network Named User Licensing to change users? How often?I couldn't find a clear answer online - so asking here.
We just bought a Network Named User License last week for two users. Two questions:
1. Post install, can we update the users in the Options File?
2. Any limits on how often can we change those users?Patrick Lysaghthttps://ww2.mathworks.cn/matlabcentral/profile/authors/17956746-patrick-lysaghttag:ww2.mathworks.cn,2005:Question/5140262020-03-30T15:52:06Z2020-03-31T16:28:07ZPlotting in 3D many sets of x and y values against a third axis timeHi,
So through an experiment, I have hundreds of sets of 2048 x and 2048 y values which I want to plot against eachother over time. I think what I might be looking for is a surface plot, however when I looked at the documentation and tried it with some dummy numbers, it didn't play nicely.
Just to be clear, I have all the data in CSV files, so I have the x values which are wavelength which are always the same. I then have the y values which are absorption which are the things changing and finally I have time which I would like to plot on the z axis. The time corresponds to one set of 2048
How would I go about doing this? I've been sat here thinking for a couple of hours now and can't think of a good way to do it.
Thank you!
P.S I attached a badly drawn image of how I'm hoping it'll lookCallum Breslinhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13868832-callum-breslintag:ww2.mathworks.cn,2005:Question/5134172020-03-27T16:50:35Z2020-03-31T16:24:28ZVLookup Multiple Conditions if statementsHi
I was wanting to modify this code to perform a VLookup on 2 columns and return the element of one of the correspoding column element in the same row?
Can someone please assist me on the if statements for this function?
Here is a function I found on Mathworks that I would like to modify: So instead of having one lookup column I need 2.
https://www.mathworks.com/matlabcentral/fileexchange/29233-vlookup-similar-to-ms-excel-function
Jameshttps://ww2.mathworks.cn/matlabcentral/profile/authors/3309541-jamestag:ww2.mathworks.cn,2005:Question/5143522020-03-31T16:21:57Z2020-03-31T16:21:57ZConverting a Cell of Cells into an Array of a String Column and Double Column I have a 5x2 cell made up of cells. It is set up like this:
Red Car 50
Blue Car 45
Green Car 30
Black Car 60
Yellow Car 55
I need to convert the first column into strings, and the second column into a double. Is there anyway I can do this easily? Pathttps://ww2.mathworks.cn/matlabcentral/profile/authors/17325667-pattag:ww2.mathworks.cn,2005:Question/5140532020-03-30T17:23:17Z2020-03-31T16:21:11ZParallel optimization hanging on getCompleteIntervalsI'm using a cloudcentre cluster with parpool and the optimization runs until suddenly hanging. The code does not always hang but does 9/10 times. Suspected deadlock but I have made sure each worker has the files it requires. After it hangs I can exit with ctr-c but i have to restart the server in order to get the optimization running again else it hangs waiting for the pool to be ready.
Init code
c = parpool('AttachedFiles',{'OptimiseModel.m','decreasing_amplitude_01.mat','ArmModelV2.slx','MapData.m','sim_model_test.m','slprj'});
mpiSettings('DeadlockDetection','on')
mpiSettings('MessageLogging','on')
mpiSettings('MessageLoggingDestination','CommandWindow')
My obj function optimise model runs a simulink model with passed values from the particle swarm algorithm
if init == true
simIn = MapData;
init = false;
end
simOut = sim(simIn);
RMSE = simOut.get('rmse');
each worker has it's own copy of simin and the init stuff is a hack to allow the fuction to be evaluated by the client instance which happens once at the beginning of the particleswarm algo. (Don't know why)
spmd
model = load_system('ArmModelV2');
set_param(model, 'SimulationCommand', 'stop')
set_param(model,'FastRestart','on');
set_param(model,'SimulationMode','Accelerator');
set_param(model,'AccelVerboseBuild','on')
simIn = MapData();
end
~~~~~~~~~~~~
fun = @(x)OptimiseModel(init,MCV_B,x(1),x(2),x(3),x(4),x(5),VMO_B,x(6),x(7),x(8),MCV_T,x(9),x(10),x(11), ...
x(12),x(13),VMO_T,x(14),x(15),x(16),x(17),x(18),x(19),x(20),x(21),x(22),x(23),x(24),x(25),x(26),x(27));
options = optimoptions('particleswarm','UseParallel',true,'UseVectorized',false,'PlotFcn','pswplotbestf');
[x,rmse_best] = particleswarm(fun,27,lb,ub,options);
All looks good until out of nowhere the workers stop running the obj function and the code hangs here which is part of the src for remoteparfor:
while isempty(r)
assert(obj.NumIntervalsInController > 0, ...
'Internal error in PARFOR - no intervals to retrieve.');
r = q.poll(1, timeUnitSeconds);
obj.displayOutput();
WHY? Can anybody help me? Can provide more of the code if required (I didn't include all as most is irrelevent - at least i thought so). Any suggestions on further debugging strategys would be great also.
Thanks alot!
EDIT Code works in serialSamuel Nathanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14217286-samuel-nathantag:ww2.mathworks.cn,2005:Question/2728882016-03-11T17:27:40Z2020-03-31T16:20:58ZPlot a Heart using matlabCardioid is represented in polar coordinates as r= 2*a (1+ cosb)
Write a program that plots a cardioid for a = 2 and b = 0 to 2pi in increments of 0.01.
Convert this Cartesian coordinates using the pol2cart function and plot this as x and y.
Make it upright (turn).
Make the figure window background equal to pink using the following RGB vector: [1 0.6 0.78].
Change the front name on the x-axis to "Arial" and change the font size on the axes to size 20.
Make the line curve equal to the same color as the figure window and make the line curve stroke equal to 5.
Add a title to the graph that says "I Love MATLAB".Gabrielle Mesquitahttps://ww2.mathworks.cn/matlabcentral/profile/authors/7490757-gabrielle-mesquitatag:ww2.mathworks.cn,2005:Question/5138672020-03-30T05:49:40Z2020-03-31T16:20:32Zproblem while executing multi thresholdingHi,
I have 4 images extracted in the form of contrast,energy,homogeneity,correlation from my input Image.
by searching minimum and maximum pixel values of each seperate classes(say waterbody) for all the above mentioned 4 Images
i have applied all thresholding values to energy image
now i wanted to assign 3 colours to 3 classes but i could assign one colour to one class at a time.
any kind of suggestion is welcome.
for i=1:r
for j=1:c
if data1(i,j)==80 && data2(i,j)==90 && data3(i,j)==180 && data4(i,j)==170
R(i,j)=0;%where R,G,B is a dummy matrix contains stacked layers of data1
G(i,j)=0;
B(i,j)=255;
if data1(i,j)==200 && data2(i,j)==70 && data3(i,j)==120 && data4(i,j)==210
R(i,j)=0;
G(i,j)=255;
B(i,j)=0;
end
end
end
endsowjanya devarakondahttps://ww2.mathworks.cn/matlabcentral/profile/authors/15057065-sowjanya-devarakondatag:ww2.mathworks.cn,2005:Question/5143512020-03-31T16:20:15Z2020-03-31T16:20:15Z How can I implement fft manually (not using the matlab function) to an audio as input signal?Hi there I need help with manual implementation of the fast fourier transform (fft), I know there is a function in matlab that does it automatically. But what I need is the development of this function to be applied to an audio signal as input (directly from a microphone or a previously recorded audio). If you can help me with that implementation, I would really appreciate it and if you can explain a little about how to apply said implementation to the input signal (audio).José Díazhttps://ww2.mathworks.cn/matlabcentral/profile/authors/18011665-jose-diaztag:ww2.mathworks.cn,2005:Question/5143482020-03-31T16:18:42Z2020-03-31T16:20:01ZInsufficient number of outputs from right hand side of equal sign to satisfy assignment.Hello
I am new to Matlab. I am trying to execute a script which has PID modelled. There is one main script which has overall code to be simulated and another script has PID controller. I am calling the main script which will call the PID controller function .Everytime i try to execute the main sscript it throws error as
"Insufficient number of outputs from right hand side of equal sign to satisfy assignment." .
Error in simulate (line 97)
[in,controller_params] = controller(controller_params,thetadot);
the variable controller_params is a structured array.
The function defined in PID controller script is :
function c = PID()
c = @(state, thetadot) pid_controller(state, thetadot);
end
function [inputs,state] = pid_controller(state, thetadot)
% Rest of the Code
end
I am unable to debug this error. Please help in understanding scenarios when it occurs and how do i resolve it.
ThanksAshish Kumar Vishwakarmahttps://ww2.mathworks.cn/matlabcentral/profile/authors/8652262-ashish-kumar-vishwakarmatag:ww2.mathworks.cn,2005:Question/5143502020-03-31T16:19:12Z2020-03-31T16:19:12Zommon numbers between arraysHello,
I want to write a function that list out all common numbers between at least two array in a cell consisting of many arrays.
For instance, assume you have a cell array A = {[1,2,3], [3 4 5 6], [3 7 8 2], [11 3 15]}.
the result must be
A{1} = 2,3
A{2} = 3
A{3} = 3,2
A{4} = 3
Thank you a lot
Mo Hhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13423509-mo-htag:ww2.mathworks.cn,2005:Question/5143492020-03-31T16:19:04Z2020-03-31T16:19:04Z How to store some values in a txt file from a loop?file = dir ('*.dat')
for i = 1: lenght(file);
data = fopen(file(i).name);
soil = fread(data,[1000 1000], 'float32');
teste = find(soil<0);
soil(teste) = NaN;
soil_end = soil/6;
save (soil_end)
end
I have an .m file that opens binary data and extracts soil information from it and divides the values found by 6. I would like to store the value of each loop interaction. However, after each loop, the previous value is overwritten, is there a way I can save them all in a .txt file?
Many thanks in advance for your help!Amanda Queirozhttps://ww2.mathworks.cn/matlabcentral/profile/authors/18011377-amanda-queiroztag:ww2.mathworks.cn,2005:Question/4666482019-06-12T04:00:00Z2020-03-31T16:18:43ZHow to reopen MATLAB scripts/function when the editor was accidentally closed?How to reopen MATLAB scripts/function when the editor was accidentally closed?
MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ww2.mathworks.cn,2005:Question/5143412020-03-31T15:55:33Z2020-03-31T16:16:40ZI am doing triple integration by matlab and some error displayed.Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.
Error in integral3>@(y,z)FUN(x(1)*ones(size(z)),y,z) (line 138)
@(y,z)FUN(x(1)*ones(size(z)),y,z), ...
Error in integral2Calc>integral2t/tensor (line 237)
Z1 = FUN(X(VTSTIDX),Y(VTSTIDX)); NFE = NFE + 1;
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral3/innerintegral (line 137)
Q1 = integral2Calc( ...
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral3 (line 121)
Q = integralCalc(@innerintegral,xmin,xmax,integralOptions);
I believe the frist error is caused by my constant setting, how to change the type of the constant type?
For me, I just input k=50 to do it. any advice to me?LA Leunghttps://ww2.mathworks.cn/matlabcentral/profile/authors/17791620-la-leungtag:ww2.mathworks.cn,2005:Question/4447842019-02-13T15:56:09Z2020-03-31T16:16:16ZWrite a function called max_sum that takes v, a row vector of numbers, and n, a positive integer as inputs. The function needs to find the n consecutive elements of v whose sum is the largest possible. In other words, if v is [1 2 3 4 5 4 3 2 1] and n is 3, it will find 4 5 and 4 because their sum of 13 is the largest of any 3 consecutive elements of v. If multiple such sequences exist in v, max_sum returns the first one. The function returns summa, the sum as the first output argument and index, the index of the first element of the n consecutive ones as the second output.
I tried the follwing code but when there are two occurences for the same number, they both get removed in the same iteration and thus causes trouble.
function [summa, index] = max_sum(v,n)
summa = 0;
i = 0;
j = v;
m = [];
while i < n
summa = summa + max(j);
b = find(v==max(j));
m = [m b];
j = j(j<max(j));
i = i + 1 ;
end
t = sort(m);
index = t(1,1);
end
Ajai Kannanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14615080-ajai-kannantag:ww2.mathworks.cn,2005:Question/5143402020-03-31T15:53:45Z2020-03-31T16:16:12ZHow could I solve the problem of if statement for even and odd values?Whenever I inter any values of N and Z (even-even,odd-even,even-odd,odd-dd) I got only the last result in the condition
here is the code
Z=input('Z: ')
N=input('N: ')
if mod(Z,2)&& mod(N,2)
a=-29.3860;b=-1.1561;c=1.5857;d=0;e=2050;f=0;
elseif mod(Z,2)&& mod(N,1);
a=-29.0583;b=-1.016;c=1.6475;d=0.0426;e=-1.3405;f=6.8970;
elseif mod(Z,1) && mod(N,2);
a=-31.6038;b=-1.0003;c=1.6943;d=2.6263;e=-3.5278;f=-0.0039;
else mod(Z,1)&& mod(N,1);
a=-28.2580;b=-1.0811;c=1.6290;d=0.8047;e=-1.8276;f=3.6070;
endBajdar Nourhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11257712-bajdar-nourtag:ww2.mathworks.cn,2005:Question/5143472020-03-31T16:15:54Z2020-03-31T16:15:54Z IK of a 3R planar manipulator.You will be supplied with a solution of the 2R planar manipulator IK using the ANFIS tool from the MATLAB Fuzzy Logic Toolbox. You are required to extend this to model the IK of a 3R planar manipulator. The aim here is to train the system with a known closed-form forwards kinematics solution at a fixed number of positions and then for ANFIS to provide approximate solutions to the IK over the whole usable workspace of the manipulator.
Compare the ANFIS model with a Neural Network. This could be implemented using any of the Architectures which have been taught on the module but the mostobvious choice would be either a MLP or RBF type of network. This should be implemented using the MATLAB Neural Network Toolbox.Khalid Alhinaihttps://ww2.mathworks.cn/matlabcentral/profile/authors/17010944-khalid-alhinaitag:ww2.mathworks.cn,2005:Question/5141662020-03-31T00:43:36Z2020-03-31T16:15:23ZComparing numerical values of a 5x2 cellHello,
I am trying to compare all values in a 5x2 array that are below a certain threshold, and preserve the corresponding data in its particular row. For example, let's say I have a total of 5 cars but need to check which car goes a certain speed. I have a 5x2 matrix where the first column is a string and the second column are integers. I need to develop an algorithm that will return each of the cars that is below a a certain speed, say, below equal to or below 55 mph:
Red Car 50
Blue Car 45
Green Car 30
Black Car 60
Yellow Car 55
Therefore my output would need to be:
Red Car 50
Blue Car 45
Green Car 30
Yellow Car 55
I am guessing that the best way to do this will be with a few loops and an if statement to check the condition, but I am just not sure how to go about this as I am pretty new to MatLab. Any tips would be appreciated.
Thanks,
Patrick Pathttps://ww2.mathworks.cn/matlabcentral/profile/authors/17325667-pattag:ww2.mathworks.cn,2005:Question/5143382020-03-31T15:40:29Z2020-03-31T16:15:17Z how user defined functionwrite a function Mseries to generate Nth (N>0) terms of series from:
1,2,2,4,8,32 ....... (n-1)(n-2)Ibrahim Ahmedhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14699046-ibrahim-ahmedtag:ww2.mathworks.cn,2005:Question/5143072020-03-31T14:02:00Z2020-03-31T16:14:34ZSolve numerically a system of first-order differential equationsHello everyone,
I have the following set of coupled first-order differential equations:
a*x'/z+y'=b;
x'/z-a*y'=c*sin(2*y);
z'=d*(e/z-(f+g*sin(2*y))*z);
where a, b, c, d, e, f, and g are some known parameters.
I was wondering which could be a good attempt to solve numerically this system of differential equations.
Any suggestion?Richard Woodhttps://ww2.mathworks.cn/matlabcentral/profile/authors/15810187-richard-woodtag:ww2.mathworks.cn,2005:Question/5143462020-03-31T16:13:49Z2020-03-31T16:13:49Zhow to simulate reed solomon encoding and decoding using simulink? in need of dire helpReed solomon and other encoding and decoding algorithms using simulink with awgn and M-FSK freq 470Mhz to 590MHz.
need help in this please show me the simulation and its settings. nEED THE ERROR TO BE PLOTTED IN A BER CURVEawath ramhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9988412-awath-ramtag:ww2.mathworks.cn,2005:Question/5143222020-03-31T14:48:10Z2020-03-31T16:12:43ZDot notation from stringHi,
Is there any way to convert string with dots do a dot notation?
Let S be a structure, I want to get
I store a "path" to field to a string
path = ['field1.field2.field3'];
I want to get to a specified field3, instead of
S.field1.field2.field3
I want to call it like this, without separating it by dots.
S.(path)
If I put it like this, it treats the whole string like one name of field.
The reason is that I use a loop which creates the string "path", depending on existance of fields in each "depth" - the substructures are inconsistent. I want the "depth" (number of dots) to be variable.
THXVit Krcalhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17566911-vit-krcaltag:ww2.mathworks.cn,2005:Question/5143452020-03-31T16:11:35Z2020-03-31T16:11:35ZExplain the average of 8 nearest neighbors Hi, for dead pixel replacement I came across this code from MATLAB file exchange,https://in.mathworks.com/matlabcentral/fileexchange/4551-inpaint_nans . It takes average of 8 nearest neighbors.
% % generate sparse array to average 8 nearest neighbors
% % for each nan element, be careful around edges
fda=spalloc(n*m,n*m,size(nan_list,1)*9);
% -1,-1
L = find((nan_list(:,2) > 1) & (nan_list(:,3) > 1));
nl=length(L);
if nl>0
fda=fda+sparse(repmat(nan_list(L,1),1,2), ...
repmat(nan_list(L,1),1,2)+repmat([-n-1, 0],nl,1), ...
repmat([1 -1],nl,1),n*m,n*m);
end
% eliminate knowns
rhs=-fda(:,known_list)*A(known_list);
% and solve...
B=A;
k=nan_list(:,1);
B(k)=fda(k,k)\rhs(k);
Can you please explain what is [-1, -1]and how the neighbor and its average is calculated in the above code.A Rhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12431130-a-rtag:ww2.mathworks.cn,2005:Question/5141892020-03-31T04:20:37Z2020-03-31T16:11:00ZHow do you detect duplicate values within a random array?Write a program to find if a vector of random generated integers contains any duplicate element. Return true if any value appears at least twice in the said vector and return false if every element is distinct.
I simply have no idea how to implement this. I believe this problem requires a for loop and a series of if statements.Aaron Zambiasihttps://ww2.mathworks.cn/matlabcentral/profile/authors/17297176-aaron-zambiasitag:ww2.mathworks.cn,2005:Question/5143442020-03-31T16:09:34Z2020-03-31T16:10:16ZSymbolically Solving a multi-variable system of three equations for three variables How can I find symbolic solutions for a,b, and c expressing them with respect to the other variables using the system of equations
(-2Nsinθ)/3=mL(b)
c=-(5bLcosθ)/6+(5(a^2)Lsinθ)/6
N=m( (5bLsinθ)/6+(5(a^2)L)/6cosθ +3g) Aleem Andrewhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13655223-aleem-andrewtag:ww2.mathworks.cn,2005:Question/5142332020-03-31T08:35:17Z2020-03-31T16:06:12Zfilter a timetable by dayHi!
How can I create timetable that only groups the information from the following timetable by day?
timeStamps = datetime([2017 3 4; 2017 3 5; 2017 3 4; 2017 3 5; 2017 3 4; 2017 3 5; 2017 3 4; 2017 3 5]);
hour = [8 8 8 8 9 9 9 9]';
Volume = [5 10 15 20 25 30 35 40]';
Price= [40 35 30 25 20 15 10 5]';
T= table(timeStamps, hour, Volume, Price)
TT= table2timetable(T)
This is just an example, my real timetable is composed of several days, perhaps with a for loop?Angelavtchttps://ww2.mathworks.cn/matlabcentral/profile/authors/17242946-angelavtctag:ww2.mathworks.cn,2005:Question/3724032017-11-24T05:00:00Z2020-03-31T16:05:25ZHow to use ArUco marker with the openCV support package of MATLAB and the Computer Vision System Toolbox. [R2017b]Is there a MATLAB Toolbox which supports the usage ArUco markers, which are part of OpenCV?
MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ww2.mathworks.cn,2005:Question/5143432020-03-31T16:01:21Z2020-03-31T16:04:41ZWhy am I getting this error??!! #fminconI am getting the following error in my MATLAB code. I have already checked i hvae these functions on my computer.
Check for missing argument or incorrect argument data type in call to function 'classifyBoundsOnVars'.
Error in fmincon (line 525)
xIndices = classifyBoundsOnVars(l,u,sizes.nVar,true);
Error in optm (line 7)
[x,fval] = fmincon(@optmequation,x0,[],[],[],[],[],[],@constraint,options)Charlotte Massiehttps://ww2.mathworks.cn/matlabcentral/profile/authors/17977079-charlotte-massietag:ww2.mathworks.cn,2005:Question/5143192020-03-31T14:32:42Z2020-03-31T16:04:23ZRegression Learner / Retrain ModelHello,
I used the Regression Learner to build a medium tree model to make predictions. Then I exported it to the workspace and generated the code to retrain the model.
My question is: Will the old data be overwritten when I retrain the model or is the model expanded and contains all data?Christophhttps://ww2.mathworks.cn/matlabcentral/profile/authors/10231903-christophtag:ww2.mathworks.cn,2005:Question/5142462020-03-31T10:04:11Z2020-03-31T16:04:02ZCalculating with Methods from ClassesHi,
I'm currently getting into classes and methods, due to a project I'm working on. I have a function which needs a whole lot of other funcions to calculate it's variables.
Until now i made a Class containing all the functions I need. Now I want to give the Class the needed Properties and want it to automatically run every function in the Class and print out the final result.
I have quite a hard time finding a solution for that because I don't really now how/where to start. To begin with, I don't even know if classes are able to do what I want.
Has anybody some advice? It would be greatly appreciated!
Greetings,
LeonLeon Stolphttps://ww2.mathworks.cn/matlabcentral/profile/authors/17749366-leon-stolptag:ww2.mathworks.cn,2005:Question/5142822020-03-31T12:41:57Z2020-03-31T16:03:50ZAdding rows to matrix conditionallyI have long datafiles that I need to alter and cannot figure out how to do this.
The simplified version of what I'm trying to do is:
x = 1 20
3 50
6 10
Column 1 is time (t) (sec 1, 3, 6) and col 2 the values.
I want to create a new matrix with time axis with 1 sec interval and that the values (col 2) are repeated until next (t) ( in col1)
The resulting matrix should be:
x2 = 1 20
2 20
3 50
4 50
5 50
6 10
Sorry about the elementery question, I'm a newbyHOlhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17825628-holtag:ww2.mathworks.cn,2005:Question/5142802020-03-31T12:33:29Z2020-03-31T16:02:11Zsscanf not working for text on multiple lines.I'm trying to read text from a file and put it into various collums. It works when I use the following txt and script:
My txt file looks like:
{co-ordinates 1.5 2.5 4.8 weighting 11.713}{co-ordinates 2.5 2.8 1.7 weighting 21.4}{co-ordinates 1.5 2.5 4.8 weighting 11.7}
My code looks like:
fopen practice2.txt
str = fileread('practice2.txt')
mat = sscanf(str,'{co-ordinates%f%f%f weighting%f}',[4,Inf]).'
mat =
1.5000 2.5000 4.8000 11.7130
2.5000 2.8000 1.7000 21.4000
1.5000 2.5000 4.8000 11.7000
Now im trying to use a different txt file that looks like this:
{
co-ordinates 102.10 93.30 128.50
weighting 1.000000}
{
co-ordinates 99.60 98.50 124.00
weighting 0.622901
}
and now all of a sudden the code doesn't work at all!? Any idea why it's no longer working and how to fix it? Thanks!Hannah Taylorhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17221934-hannah-taylortag:ww2.mathworks.cn,2005:Question/5143352020-03-31T15:27:08Z2020-03-31T16:00:44ZHow can I measure in a exact point of a electronic circuit each cycle in Simulink?Dear sir,
I am trying to simulate a buck circuit in Simulink. I have the circuit and I probe it in open loop and it works. The problem is when I try to work in close loop (I use a PWM control of the inductor current).
I need the value of the current in the inductor. This shape is triangular. I put a current sensor in my circuit and I get it. But for my control, I want to measure in the middle of the rising edge, because I need the average current. How can I do it?. I know that this point is in the middle of my duty cycle. I attach a capture of my circuit.
Thank you very much for your time.
Álvaro Morales Muñozhttps://ww2.mathworks.cn/matlabcentral/profile/authors/18010856-alvaro-morales-munoztag:ww2.mathworks.cn,2005:Question/5143422020-03-31T15:58:43Z2020-03-31T15:58:43ZMultiple ego vehicle with same sensor added to the scenario at the same point in different simulation timeHi,
I want to add multiple ego vehicles in the driving scenario with same characteristics and sensors at different time in the simulation from the starting point of the road? Can someone help me with this please? Thank youMudasser Serajhttps://ww2.mathworks.cn/matlabcentral/profile/authors/5633710-mudasser-serajtag:ww2.mathworks.cn,2005:Question/5140472020-03-30T16:47:53Z2020-03-31T15:57:06ZEvaluating unknown variable for a series of x values and storing the data to be used laterHi,
I have two questions
1) I have an equation piecewise equation of the form z=f(x+y). I know z, y and have to solve it for x. The equation is very complex and does not give a real solution. The best approach in that case is I solve it numerically i.e., for a given set of z, y, evaluate x and store it as an array of x, y, z and reuse
later.
I have tried using many things including feval, subs etc. But that seems to require that my unknown variable is on LHS. Can you please suggest a way of doing it?
2) How do I store the values of x, y, z in an array that I can use again?
Regards,
Heena
Heena Khanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17997288-heena-khantag:ww2.mathworks.cn,2005:Question/5119182020-03-20T12:32:54Z2020-03-31T15:56:45ZYOLO V2 with greyscale FITS images (telling me it's expecting rgb)Hello,
I am trying to train a YOLO v2 networks using a fits format of image. I have modified the 'imageDatastore' function to read them instead of more traditional data formats.
[table1]=read_write_fits(1,'path_to_dir/');
traintbl=table1(:,'VAR');
imdsTrain = imageDatastore(table1{:,'imagefilename'},'ReadFcn',@fitsreadTwo);
bldsTrain = boxLabelDatastore(traintbl);
trainData = combine(imdsTrain, bldsTrain);
'fitsreadTwo' is present due to the issue that i'm having. when i attempt to use the 'yoloyv2Layers' function, it's telling me that it's expecting [height width 3] images despite mine being in greyscale 11 bit. When I input the following code and attempt to put [Height Width 1](greyscale) the yolov2layers function is telling me It's expecting [height width 3]. How is it coming up with what it's expecting? Why can I not modify it to have the correct input size? I've even tried swapping out the first layer of the network, but that creates compile errors down the line. Any help here or general guidelines will be spectacular. Thanks.
numAnchors = 7;
[anchorBoxes,~] = estimateAnchorBoxes(trainData,numAnchors);
featureExtractionNetwork = resnet50;
layers = [imageInputLayer([height width 1],'Name','input_1') ];
featureLayer = 'activation_40_relu';
lgraph=layerGraph(featureExtractionNetwork);
inputSize = [height width 3];
lgraph_rl = replaceLayer(lgraph,'input_1',layers);
numClasses = 1;
lgraph2 = yolov2Layers(inputSize,numClasses,anchorBoxes,lgraph_rl,featureLayer);
Here is my fix for the problem: I make the greyscale image into an rgb image with the following code:
function [image]=fitsreadTwo(filename)
%the purpose of this script is to read a fits image and store it as an RGB
%even tho it is greyscale.
image=fitsread(filename);
map=hsv(8200);
image=ind2rgb(image,map);Ryan Comeauhttps://ww2.mathworks.cn/matlabcentral/profile/authors/15784442-ryan-comeautag:ww2.mathworks.cn,2005:Question/5143392020-03-31T15:50:15Z2020-03-31T15:50:15ZTF of Laplace transform of squarerootHello,
This could be an easy question for many but for the life of me i could not solve it
I have a
syms x y
laplace(sqrt(x))
ans =
pi^(1/2)/(2*s^(3/2))
Now I want to convert laplace domain Numerator and denominator to TF(num,den) so that i can use it further.
How to achieve this?Rahul Nadgoudahttps://ww2.mathworks.cn/matlabcentral/profile/authors/6175212-rahul-nadgoudatag:ww2.mathworks.cn,2005:Question/4474602019-02-28T09:15:00Z2020-03-31T15:50:04Zfailed to compile C code with MinGW on windows 10I am trying to build model from simulink (Ctrl + B in Simulink, export to C code) and got an error: "Unable to locate template makefile: rtwsfcnfmi_lcc64.tmf". I am using Matlab 2016b on window 10 platform. I have installed MinGW64 4.9.2 Compiler on my machine, which is supposed to support Matlab 2016b. (The system target file in the parameter configuraiton is rtwsfcnfmi.tlc and the template make file is rtwsfcnfmi_tmf.)
When I had a closer look, the exporting is stuck in the function get_tmf_for_target.m (under \2016b\rtw\rtw). There is one line called comp = rtwprivate('rtwParallelBuildCompiler','get'); The value I got is comp=0, looks very much matlab could not find a compiler. However, when I check the compiler installtion with mex -setup -v, it seems that the compiler is installed correctly and I got the following message:
... Looking for compiler 'MinGW64 Compiler (C)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\mingw-w64\x86_64-4.9.2-posix-seh-rt_v4-rev4\mingw64\').
... Looking for file 'C:\mingw-w64\x86_64-4.9.2-posix-seh-rt_v4-rev4\mingw64\bin\gcc.exe' ...Yes.
... Looking for folder 'C:\mingw-w64\x86_64-4.9.2-posix-seh-rt_v4-rev4\mingw64' ...Yes.
Found installed compiler 'MinGW64 Compiler (C)'.
So I am wondering what caused the error? I notice that MigGW64 does not support Matlab compiler nor Matlab compiler SDK for version 2016b, could that be the reason?
Lei Xuhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14825532-lei-xutag:ww2.mathworks.cn,2005:Question/5106932020-03-13T11:34:15Z2020-03-31T15:46:19ZSimulink code generation for STM32: how to generate the .bin file?Hi everyone,
I have bought a STM32F4-Discovery Board DTM32F429I-Disc1, and my intention is to work in Matlab-Simulink.
This is the process I have followed:
INSTALLATION: Matlab/Simulink R2018b 64bit with toolboxes like Embedded Coder
INSTALLATION: Matlab/Simulink HW support package "Embedded Coder Support Package for STMicroelectronics Discovery Boards"
INSTALLATION: STM32-MAT/TARGET from ST
INSTALLATION: STM32CubeMX from ST
INSTALLATION: STM32CubeIDE_1.3.0 from ST
Within STM32CubeMX, generate the .ioc file for the right board/MCU in order to blink the green LED:
Give it the name "BlinkLED"
PG13 as GPIO_Output and with a name "GreenLED"
Select Toolchain\IDE = STM32CubeIDE (Project Manager \ Code Generator)
Within Matlab-Simulink:
Add the STM32-MAT/TARGET path to Matlab's path (pathtool)
Create a new simulink model
Within the configuration parameters:
Solver: Fixed-step, stop time = inf, step time = 0.001
Code generation: Select the target file as "stm32.tlc" (This takes a while...)
Code generation: Within the STM32 options, update the STM32CubeMx path
Open the Simulink library and at the bottom should be the library for "Target support package - STM32 adapter"
Select block "STM32_Config" and link to the .ioc file generated within STM32CubeMx
Select block GPIO_Write and configure the pin 13
Build (Ctrl+B)
SUCCESSFUL!
However, I can not find a .bin file that can programmed on the board using the "ST-Link Utility". Any ideas?
Other option is to open the .project generated within STM32CubeIDE, but there are seem to be some files missing?
Thanks a lotDionisio Cagigas Fojacohttps://ww2.mathworks.cn/matlabcentral/profile/authors/17119487-dionisio-cagigas-fojacotag:ww2.mathworks.cn,2005:Question/5141512020-03-30T22:34:51Z2020-03-31T15:43:29ZFrom nested structure to table in one line of codeI have a structure S with n fields S_field_1, S_field_2,…S_field_n. Each field contains a structure with the same number m and name of fields field_1, field_2…field_m.
How do I get a nxm table with variables field_1, field_2…field_m with a single line of code?
Thank you!Giovanni Barbarossahttps://ww2.mathworks.cn/matlabcentral/profile/authors/8731259-giovanni-barbarossatag:ww2.mathworks.cn,2005:Question/5134192020-03-27T16:58:45Z2020-03-31T15:41:20ZQuadratically constrained linear maximisation problem: issues with fminconI would like to solve the following quadratically constrained linear programming problem.
I have written a Matlab code (R2091b) that solve the problem using Gurobi. Now, I would like to rewrite the code using fmincon instead of Gurobi. This is because the optimisation problem will have to be solve thousands of times and Gurobi's academic license does not allow to parallelise via array jobs in a cluster. However, I'm encountering a huge problem: Gurobi takes 0.23 second to give a solution, fmincon takes 13 sec. I suspect this should be due to my mistakes/inefficiences in providing gradient, hessian, etc. Could you kindly help me to improve below?
Also, Gurobi gives me 0.2 as solution, fmincon gives 0.089. Can the accuracy of fmincon be improved without trying other starting points?
This is my code with Gurobi
clear
rng default
load matrices
%1) GUROBI
model.A=[Aineq; Aeq];
model.obj=f;
model.modelsense='max';
model.sense=[repmat('<', size(Aineq,1),1); repmat('=', size(Aeq,1),1)];
model.rhs=[bineq; beq];
model.ub=ub;
model.lb=lb;
model.quadcon(1).Qc=Q;
model.quadcon(1).q=q;
model.quadcon(1).rhs=d;
params.outputflag = 0;
result=gurobi(model, params);
max_problem_Gurobi=result.objval;
This is my code with fmincon
%2) FMINCON
options = optimoptions(@fmincon,'Algorithm','interior-point',...
'SpecifyObjectiveGradient',true,...
'SpecifyConstraintGradient',true,...
'HessianFcn',@(z,lambda)quadhess(z,lambda,Q));
fun = @(z)quadobj(z,f.');
nonlconstr = @(z)quadconstr(z,Q,d);
[~,fval] = fmincon(fun,z0,Aineq,bineq,Aeq,beq,lb,ub,nonlconstr,options);
max_problem_fmincon=-fval;
function [y,yeq,grady,gradyeq] = quadconstr(z,Q,d)
y= z'*Q*z -d;
yeq = []; %no quadratic inequalities
if nargout > 2
grady = 2*Q*z;
end
gradyeq = []; %no quadratic inequalities
end
function hess = quadhess(z,lambda,Q) %#ok<INUSL>
hess = 2*lambda.ineqnonlin*Q;
end
function [y,grady] = quadobj(z,f)
y = -f'*z;
if nargout > 1
grady = -f;
end
Further, if I run the code with fmincon with as starting point the optimal point given by Gurobi, I still get the solution 0.089 (instead of 0.2 as in Gurobi). Why?
%3) FMINCON
z0=result_Gurobi.x;
options = optimoptions(@fmincon,'Algorithm','interior-point',...
'SpecifyObjectiveGradient',true,...
'SpecifyConstraintGradient',true,...
'HessianFcn',@(z,lambda)quadhess(z,lambda,Q));
fun = @(z)quadobj(z,f.');
nonlconstr = @(z)quadconstr(z,Q,d);
[~,fval] = fmincon(fun,z0,Aineq,bineq,Aeq,beq,lb,ub,nonlconstr,options);
max_problem_fmincon=-fval;
function [y,yeq,grady,gradyeq] = quadconstr(z,Q,d)
y= z'*Q*z -d;
yeq = []; %no quadratic inequalities
if nargout > 2
grady = 2*Q*z;
end
gradyeq = []; %no quadratic inequalities
end
function hess = quadhess(z,lambda,Q) %#ok<INUSL>
hess = 2*lambda.ineqnonlin*Q;
end
function [y,grady] = quadobj(z,f)
y = -f'*z;
if nargout > 1
grady = -f;
end
end
CThttps://ww2.mathworks.cn/matlabcentral/profile/authors/10950381-cttag:ww2.mathworks.cn,2005:Question/5143252020-03-31T14:58:42Z2020-03-31T15:37:56ZHow to use bar function?Hey all,
I have X (12 x 1 cell) and Y (12 x 1 cell). I want to have a plot like this: (x is blue and y is green)
I tried so many ways, All unsuccessful and gives me various errors.
If it's a matter, this is just for January. In the next step I want to have all months in one graph.
can anybody help me?
Thank you all.Behzad Navidihttps://ww2.mathworks.cn/matlabcentral/profile/authors/15525777-behzad-naviditag:ww2.mathworks.cn,2005:Question/1802402015-02-25T09:51:50Z2020-03-31T15:37:28ZHow to paste nicely into Excel from MATLAB variable editor?One can readily paste data from Excel into a MATLAB cell array in the variable editor using Paste Excel Data (Ctrl-Shift-V), but how exactly does one reverse this operation?
I find cells that contain [] become strings in Excel, where I expect blank cells, and strings get unwanted quotes at the start and end.
The net result of this is if you copy and paste some cells in Excel comprising some text, some numeric and some blanks into a MATLAB cell array - it looks fine in MATLAB - but when you copy back to Excel you don't have what you started out with.
Easy copy / paste between Excel and MATLAB should be a breeze in 2015, shouldn't it? What am I doing wrong? Perhaps there is or needs to be a "Copy Excel Data" function to match "Paste Excel Data" (although it is nicer to just use standard Ctrl+C, Ctrl+V)?
Thanks for reading this.
Julianhttps://ww2.mathworks.cn/matlabcentral/profile/authors/72177-juliantag:ww2.mathworks.cn,2005:Question/5143372020-03-31T15:35:01Z2020-03-31T15:35:01ZAny notes or examples available on calculating the modulation transfer function of an imaging system in matlabHi everyone,
Just wondering if anyone has experience of using matlab to calculate the modulation transfer function of an imaging system? I've been tasked with doing this instead of my usual lab work as I'm currently working at home and don't really know where to start. Parameters to change in the model should be lens width and source extent.Janna Hinchliffhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14319116-janna-hinchlifftag:ww2.mathworks.cn,2005:Question/5141852020-03-31T04:06:58Z2020-03-31T15:32:16ZHow to Measuring Peak WidthsHi,
New to Matlab and thought I'd try measuring peak width from Calcium transits in beating cardiomyocytes. I've succedded in finding peak heights and making a graph which displays the peak widths (see attached figure)
This may sound simple, but how can I generate a numerical integer, or table which provides the widths of each peak. Ideally, I would use this to find the peaks (i.e., intensity), and widths (i.e., duration) of calcium transits in multiple cell lines. A bonus would be to measure the time at 90% return to baseline.
Thanks for the help.Aidan Fenixhttps://ww2.mathworks.cn/matlabcentral/profile/authors/15899720-aidan-fenixtag:ww2.mathworks.cn,2005:Question/5140592020-03-30T17:40:02Z2020-03-31T15:32:04ZObjective function increases but solver converges --- Why?Hi All,
I am trying to solve a constrained optimization problem in fmincon
But I am not sure why the solver converges when the value of the objective function keeps increasing. In the problem I actually try to minimize the cost function.
First-order Norm of
Iter F-count f(x) Feasibility optimality step
0 10 4.832863e+02 9.049e+00 4.227e-02
1 21 1.102633e+03 4.064e+00 1.773e+03 4.846e+02
2 31 3.135305e+03 6.418e-01 1.748e+04 3.303e+02
3 41 3.838079e+03 1.503e-01 2.712e+04 1.434e+02
4 51 5.643491e+03 1.751e-02 1.479e+04 1.056e+02
5 64 1.104272e+04 2.133e-04 1.475e+04 4.097e+01
6 78 1.114938e+04 3.426e-07 1.583e+00 2.615e-01
7 89 1.114955e+04 3.189e-09 1.910e+01 4.891e-04
8 104 1.114956e+04 1.458e-11 3.254e-01 3.897e-06
9 119 1.114956e+04 1.779e-12 2.596e-01 3.332e-09
10 134 1.114956e+04 2.554e-13 2.519e-01 3.315e-10
11 149 1.114956e+04 4.795e-14 2.509e-01 8.456e-11
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current step is less than
the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.
I have solved the same problem without constraints and the objective function decreases with iterations
14 150 3.019962e+00 0.000e+00 2.483e-03 2.052e+03
15 160 1.582527e+00 0.000e+00 1.598e-03 1.897e+03
16 170 1.098656e+00 0.000e+00 1.042e-03 1.503e+03
17 180 9.917733e-01 0.000e+00 7.543e-04 9.265e+02
Any help in understanding why the solver converges when objective function increases in constrained case will be useful.
Side note: MATLAB version 2020a. More details on the problem here
Deepa Maheshvarehttps://ww2.mathworks.cn/matlabcentral/profile/authors/8575091-deepa-maheshvaretag:ww2.mathworks.cn,2005:Question/5136792020-03-29T04:31:37Z2020-03-31T15:31:59Zode15s meshgrid issueWhen trying to run a code created by one of my professors to be manipulated for my homework, I get an error that says:
Error in ode15s (line 294)
[kJ,kI] = meshgrid(maxK,maxK);
My code cannot run because my ode15s solver is somehow incorrect on y computer even though I have never manipulated it before. Please send help.
Thank you,
KaylaKayla Jacobshttps://ww2.mathworks.cn/matlabcentral/profile/authors/8625509-kayla-jacobstag:ww2.mathworks.cn,2005:Question/5141912020-03-31T04:49:30Z2020-03-31T15:28:29Zfmincon converges to solution using interior-point but not using sqpHi All,
I am solving an optimization problem using fmincon. The solver converges to a solution using interior-point algorithm but fails when I use sqp.
line 9 in the file attached:
opts_fmin = optimoptions('fmincon','Display','iter', 'Algorithm', 'sqp-legacy'); %interior-point
Could someone help me in understanding why this happens?
The error that I get is in the computation of objective function after 70 iterations
Matrix dimensions must agree.
Error in cse_03_19_20/objfun (line 39)
f = sum((phi(:) - phi_tilde(:)).^2);
Error in evalObjAndConstr
Error in sqpLineSearch
MATLAB version used: 2020aDeepa Maheshvarehttps://ww2.mathworks.cn/matlabcentral/profile/authors/8575091-deepa-maheshvaretag:ww2.mathworks.cn,2005:Question/5142952020-03-31T13:31:00Z2020-03-31T15:27:34ZConverting input matrix A with size 4x3 into B matrix with size 12x3 with coordinates in matrix AHello!
So i have this input matrix A with size that varies but for example let's asume size is 4x3.
where
A=[a11 a12 a13;
a21 a22 a23;
a31 a32 a33;
a41 a42 a43]
and want to form another matrix B with the respective coordinates in the matrix for rows and columns and the value itself, resulting in a 12x3 matrix.
So in my case i want B= i j aij for all rows for all aij values in matrix A
B=[1 1 a11;
1 2 a12;
1 3 a13;
2 1 a21;
2 2 a22;
2 3 a23;
3 1 a31;
3 2 a32;
3 3 a33;
4 1 a41;
4 2 a42;
4 3 a43]
So one row of B has 3 values: Horizontal coordinate in number of columns, Vertical coordinate in number of rows and the last value is ithe value itself located at those coordinates
I've done the task in excel with index function but the txt input and large format of input matrix (can reach 10000x10000) and the variating size of the input data makes much more sense to do this in matlab.
I'm very new to matlab and need a bit of help if possible. Thank you!Adrian Asihttps://ww2.mathworks.cn/matlabcentral/profile/authors/4105708-adrian-asitag:ww2.mathworks.cn,2005:Question/5143362020-03-31T15:27:24Z2020-03-31T15:27:24Zreading a txt file using readtable, the file is contain string that is not in english languageHi
I have a problem in reading a text file that consist of strings, if the string is english, matlab does not give error, but if the string is in another language it showed as attached in the picture and the file is attached
Does any one have solution for this?
your help is appreciatedZMhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4744506-zmtag:ww2.mathworks.cn,2005:Question/1018302009-06-27T01:11:00Z2020-03-31T15:25:34ZWhy is the SUBSREF method not called when used from within a method of a class?Using the polynomial class example in the documentation, I have created a class @polynom. Within this class, I have defined a number of methods, one of which is SUBSREF. When I call any overloaded method from within a method of the polynom class, I do not run into any problems. MATLAB knows to look in the class for the method first.
I then try to subsref into my object and instead of calling the overloaded SUBSREF, MATLAB attempts to call the built-in SUBSREF. To work around this I have to explicity call SUBSREF. I would like to know why this works for all other overloaded methods.
The following is an example of calling an object's subsref from the command line:
>> p = polynom([1 2 3 4])
p =
x^3 + 2*x^2 + 3*x + 4
>> x = 2
x =
2
>> y=p(x)
y =
26
When calling y = p(x) from an overloaded method called plot:
ERROR:
>> plot(p)
Warning: Subscript indices must be integer values.
> In p:\@polynom\plot.m at line 10
??? Index into matrix is negative or zero. See release notes on changes to
logical indices.
Error in ==> p:\@polynom\plot.m
On line 10 ==> y = p(x);
To workaround this, I have to call SUBSREF explicitly:
y = polyval(p,x);
subs.type = '()';
subs.subs = {x};
y = subsref(p, subs); %should call subsref hereMathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813-mathworks-support-team