https://ww2.mathworks.cn/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-02-28T18:51:23Ztag:ww2.mathworks.cn,2005:Question/7464972021-02-16T05:17:56Z2021-02-28T18:51:23ZHow to change datenum to normal date format?Hi all,
I have tried using following command but as a result date has wrong year and they are not in sequence too:
datestr(A{1})
>>'01-Jul-4447'
'25-Jul-4447'
'18-Aug-4447'
'11-Sep-4447'
'05-Oct-4447'
'29-Oct-4447'
datetime(A{1}, 'ConvertFrom', 'datenum', 'Format', 'dd-MM-yyyy')
>>01-07-4447
25-07-4447
18-08-4447
11-09-4447
05-10-4447
29-10-4447
datevec(A{1})
>>4447 7 1 0 0 0
4447 7 25 0 0 0
4447 8 18 0 0 0
4447 9 11 0 0 0
4447 10 5 0 0 0
4447 10 29 0 0 0
I have attached a dummy data here in this link:
https://drive.google.com/file/d/1vNAVx0zDFSBiXW52j8pzwGg9mLsVZe4o/view?usp=sharing UTKARSH VERMAhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9683896tag:ww2.mathworks.cn,2005:Question/7580642021-02-27T17:43:26Z2021-02-28T18:49:56ZHow can I keep peak dataHow can I keep the blue dot data into variable to use it on other step?
Thx for all answerPhudit Kanittasuthttps://ww2.mathworks.cn/matlabcentral/profile/authors/19618179tag:ww2.mathworks.cn,2005:Question/7108932021-01-07T10:09:23Z2021-02-28T18:48:35ZHow to create a netcdf in matlab which can be read by grads without using descriptor file?I have data containing lat, lon, time and precipitation values:
lat: 128*1double
lon 256*1double
time 3652*1double
pr 256*128*3652double
I have masked my original data and now I want to create netcdf file which has all the information of original files and most importantly it can be read by grads without the use of descriptor file.UTKARSH VERMAhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9683896tag:ww2.mathworks.cn,2005:Question/7587392021-02-28T18:18:16Z2021-02-28T18:46:00ZError: Array indices must be positive integers or logical values.Here is my code:
clc;clear;
t=[0:0.5:60];
h(t)=2.03*t.^2-0.0013*t.^4+0.000034*t.^4.751;
plot(t, h(t));
xlabel('Time');
ylabel('Height(m)');
But I get this error when I try to evaluate:
Array indices must be positive integers or logical values.
I need 100 values from 0 to 60 for my graph.
Thank you! Katherine DeChambeauhttps://ww2.mathworks.cn/matlabcentral/profile/authors/20228312tag:ww2.mathworks.cn,2005:Question/7587642021-02-28T18:44:14Z2021-02-28T18:44:14ZHow can I read text files and compile a joint XY Position historyHello eveyone,
I am struggling with finding a solution to my problem. I have a json text file with XY position co-ordinates for a 2d human pose estimation. I would like to read and use particular data keypoints from the XY coordinates. Is there a way to convert the data into an array?Ross Normanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/20472567tag:ww2.mathworks.cn,2005:Question/7580092021-02-27T17:07:35Z2021-02-28T18:43:46ZDraw multiple surfaces from different tables(.mat) files. Such that the different .mat files have different Color and names should be displayed on the surfaceHello,
I would like to have to read multiple table (.mat) files from a folder and plot all the graphs in one figure like the rough diagram image I have attached. I have sent in the input files and the matlab code which runs all surfaces but does not have different color nor the names on the figure. I just want it easy to distinguish the the diffferent surfaces clearly.
Regards
AmanAmanullah Khanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/19474381tag:ww2.mathworks.cn,2005:Question/7587592021-02-28T18:43:36Z2021-02-28T18:43:36ZMatlab App connect and talk to an USB DeviceHello all,
I am programming an app to control a Spectano 100 via USB. I want to send different Values an plot some readings. I already have the GUI but I'm not getting anywhere with the programming. Here is a sample code from the manufacturer: https://documentation.omicron-lab.com/SpectanoAutomationInterface/1.60/articles/Add_AI_Reference.html
I don't know how to integrate it into my app. Do I need an extra m file?
Best regadsFabian Heynhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13811151tag:ww2.mathworks.cn,2005:Question/7568142021-02-26T09:05:44Z2021-02-28T18:42:40ZSolve non-linear equations system parametrically, Why are the answers empty?clear all;
clc;
syms X1 X2 X3 X4 X5 X6 X7 X8 X9 h k1 Lz1 k21 Lz2 k32 Lz3 a1 a2 a3 b1 b2 b3 w1 w2 w3 r1 r2 r3;
e0 = X1-1 == 0;
e1 = h*X1-k1*X7*X4==0;
e2 = X1*cos(X7*Lz1)+X4*sin(X7*Lz1)-X2==0;
e3 = -X1*X6*sin(X7*Lz1)+X4*X6*cos(X7*Lz1)-X8*X5*k21==0;
e4 = X2*cos(X8*Lz2)+X5*sin(X8*Lz2)-X3==0;
e5 = -X2*X8*sin(X8*Lz2)+X5*X8*cos(X8*Lz2)-X9*X6*k32==0;
e6 = X3*cos(X9*Lz3)+X6*sin(X9*Lz3)==0;
e7 = (a1/a2)*(b1^2+r1^2+X7^2+w1^2)-b2^2-r2^2-w2^2-X8^2 ==0;
e8 = (a1/a3)*(b1^2+r1^2+X7^2+w1^2)-b3^2-r3^2-w3^2-X9^2 ==0;
sol = solve([e0,e1,e2,e3,e4,e5,e6,e7,e8],[X1 X2 X3 X4 X5 X6 X7 X8 X9]);
Why are the answers empty?
X1: [0×1 sym]
X2: [0×1 sym]
X3: [0×1 sym]
X4: [0×1 sym]
X5: [0×1 sym]
X6: [0×1 sym]
X7: [0×1 sym]
X8: [0×1 sym]
X9: [0×1 sym]Arash Pourkazemihttps://ww2.mathworks.cn/matlabcentral/profile/authors/19550592tag:ww2.mathworks.cn,2005:Question/7587542021-02-28T18:35:37Z2021-02-28T18:35:37ZProgrammatically crop rough image to rectangle Hello MathWorks community,
I could use your help programatically cropping a matrix / image I have. I would like to find the inner bounding box, such that the box only contains the image with no 'dark' regions.
I've tried using the regionprops function already (extrema and bounding box), however the result isn't exactly what I want.
frame = img>0;
extrema = regionprops(frame,'extrema');
box = regionprops(frame,'BoundingBox');
Extrema unreliably returns the bounding edges, and BoundingBox returnes the outer bonding box which includes 'dark' regions.
Any thoughts on how to tackle this problem would be greatly appreciated!
Samantha Sheppardhttps://ww2.mathworks.cn/matlabcentral/profile/authors/16208341tag:ww2.mathworks.cn,2005:Question/7583842021-02-28T06:55:06Z2021-02-28T18:29:09ZAdding numbers in a row vectorHow can I tell the computer to do this instead of manually typing it?
a = [1,2,3];
alist = [a(1),a(1)+a(2),a(1)+a(2)+a(3)]
Played around with a for loop but it didn't do what I wanted.
Ali Fuat Yuvalihttps://ww2.mathworks.cn/matlabcentral/profile/authors/17337794tag:ww2.mathworks.cn,2005:Question/7580292021-02-27T17:15:59Z2021-02-28T18:21:19ZCiting MATLAB products or relative webpageHi all,
I read different topics about this question, but some links are no longer available and I need to know something, please. In my paper I'm talking about Simscape Multibody, but no info about its citation is present in the relative pages. Assuming a bibitem as the following one (or different one if it is more proper than this):
@misc{name,
author = "author",
title = "title",
year = "year",
url = "url",
note = "[note]"
}
what kind of argument can I insert in each section considering Simscape Multibody at the following link https://www.mathworks.com/products/simmechanics.html?
For example, at this link https://it.mathworks.com/matlabcentral/fileexchange/47417-simscape-multibody-contact-forces-library there si a section named "Cite As" where all the info are available.
What is the better way to do that?
Thanks,
best regardsGiacomo Bonafedehttps://ww2.mathworks.cn/matlabcentral/profile/authors/5752408tag:ww2.mathworks.cn,2005:Question/7586992021-02-28T17:38:59Z2021-02-28T18:20:10ZHow to center and add margin around image?Here is my code, what im trying to do is to put image I2 on top of image I1 center it and create a white margin around it that is 50 pixels. Ive googled some possible solutions for the margin and im not having any luck in implementing those solutions. Any help?
I1 = imread('blue-lake.jpg');
I2 = imread('portrait.jpg');
I1 = imresize(I1, 1);
IM2 = imresize(I2, 2);
I1 = image(I1)
hold on;
image(IM2);
Elliot Wylliehttps://ww2.mathworks.cn/matlabcentral/profile/authors/19236801tag:ww2.mathworks.cn,2005:Question/7587442021-02-28T18:18:51Z2021-02-28T18:18:51ZHow to import and read multiple .txt files where each .txt file contains multiple number of x,y,z values??I don't know how to frame my question. I was given initially a .txt file which contains a lot of x,y,z values. I was then assigned each of x, y and z values to the respective variables. Now, I was given a problem where I will be given multiple .txt files which again contains a lot x,y,z values. My task is now to investigate how to import them into matlab and extract date from them efficiently?
I would like to know your suggestions.
Thanks.srikanth thorlikondahttps://ww2.mathworks.cn/matlabcentral/profile/authors/8353272tag:ww2.mathworks.cn,2005:Question/7587342021-02-28T18:16:14Z2021-02-28T18:16:14Zhow to share the data from one app to another app in matlab app designer I know this question already asked I also going to refference document but the concept is not cleard to me.
please help me to reach out. I explained below what I want.
I have User input promt on which i taken the input as temperature value in 3 numeric EditFeild.
share that 3 numeric edit feild value to another app where another 3 numeric EditField in that I want to show average of all the temperature, maximum and minimum temperature among three .
I have added 1st button to open the 2nd app and 2nd button to get the result in other app.
I think this enough to clear the concept how to share the data from one app to another.
please suggest code for it thank you! Krutik Gujarathihttps://ww2.mathworks.cn/matlabcentral/profile/authors/18541524tag:ww2.mathworks.cn,2005:Question/7587292021-02-28T18:15:48Z2021-02-28T18:15:48ZHow can write code for Free electron energy bands FCChello
i want to write a program for '' Free electron energy bands for the FCC''According to the figure below.can write the code of this program and help me?
lusin johnsonhttps://ww2.mathworks.cn/matlabcentral/profile/authors/16600045tag:ww2.mathworks.cn,2005:Question/7587242021-02-28T18:14:46Z2021-02-28T18:14:46ZSimulink Fixed point toolHi
I have developed an application in system generator . I also had a reference .m code which I used to verify the outputs of my sys gen design
Now I want to see the effect of fixed point implementation upon the ouput accuracy.
Please guide how can I proceed
Best Regards
Uzmeeduzmeedhttps://ww2.mathworks.cn/matlabcentral/profile/authors/2196211tag:ww2.mathworks.cn,2005:Question/7587192021-02-28T18:12:47Z2021-02-28T18:12:47ZFailing to get rid of a for loop with vectorizationHello everyone, this is the for loop I'm trying to get rid of:
% Main for loop to numerically integrate the HH model
for k = 1: niter-1
% taus for m,h,n
tau_m = 1 /(alpham(V_plot(k))+betam(V_plot(k)));
tau_h = 1 /(alphah(V_plot(k))+betah(V_plot(k)));
tau_n = 1 /(alphan(V_plot(k))+betan(V_plot(k)));
% Steady state values for m, h, n
m_inf = alpham(V_plot(k))/(alpham(V_plot(k))+betam(V_plot(k)));
h_inf = alphah(V_plot(k))/(alphah(V_plot(k))+betah(V_plot(k)));
n_inf = alphan(V_plot(k))/(alphan(V_plot(k))+betan(V_plot(k)));
% Update m, h, and n using the Exponential-Euler method
m_plot(k+1) = m_inf+(m_plot(k)-m_inf)*exp(-dt/tau_m);
h_plot(k+1) = h_inf+(h_plot(k)-h_inf)*exp(-dt/tau_h);
n_plot(k+1) = n_inf+(n_plot(k)-n_inf)*exp(-dt/tau_n);
% Update conductances
gNa = gNabar*(m_plot(k+1)^3)*h_plot(k+1); %sodium conductance
gK = gKbar*(n_plot(k+1)^4); %potassium conductance
g = gNa+gK+gLbar; %total conductance
gE = gNa*ENa+gK*EK+gLbar*EL; %gE=g*E
% update vinf
V_inf = (gE + Ie(k)/A) / g;
% update tauv
tau_V = C/g;
% exponential euler for updating membrane potential
V_plot(k+1) = V_inf + (V_plot(k)-V_inf)*exp(-dt/tau_V);
end
By doing this:
% Main for loop to numerically integrate the HH model
% taus for m,h,n
tau_m = 1 ./(alpham(V_plot)+betam(V_plot));
tau_h = 1 ./(alphah(V_plot)+betah(V_plot));
tau_n = 1 ./(alphan(V_plot)+betan(V_plot));
% Steady state values for m, h, n
m_inf = alpham(V_plot)./(alpham(V_plot)+betam(V_plot));
h_inf = alphah(V_plot)./(alphah(V_plot)+betah(V_plot));
n_inf = alphan(V_plot)./(alphan(V_plot)+betan(V_plot));
% Update m, h, and n using the Exponential-Euler method
m_plot = m_inf+(m_plot-m_inf).*exp(-dt./tau_m);
h_plot = h_inf+(h_plot-h_inf).*exp(-dt./tau_h);
n_plot = n_inf+(n_plot-n_inf).*exp(-dt./tau_n);
% Update conductances
gK = gKbar*(n_plot); %potassium conductance
gNa = gNabar*((m_plot.^3).*h_plot); %sodium conductance
g = gNa+gK+gLbar; %total conductance
gE = gNa*ENa+gK*EK+gLbar*EL; %gE=g*E
% update vinf
V_inf = (gE + Ie/A) / g;
% update tauv
tau_V = C./g;
% exponential euler for updating membrane potential
V_plot = V_inf + (V_plot-V_inf).*exp(-dt./tau_V);
I attach here the 6 functions ("alphas" and "betas") and the 2 scripts ("HH" is the one with the for loop; "HH2" is the one in which I'm trying to get rid of it).
I'm not sure what I'm getting wrong. Thanks for your help!Samuele Bolottahttps://ww2.mathworks.cn/matlabcentral/profile/authors/16756884tag:ww2.mathworks.cn,2005:Question/7587142021-02-28T18:12:18Z2021-02-28T18:12:18ZHow to solve by using fmincon?Can anyone help me? How to solve this one by using fmincon? Vellapandi M Research Scholarhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14774737tag:ww2.mathworks.cn,2005:Question/7501942021-02-19T11:25:57Z2021-02-28T18:08:54ZHow to combine multiplot in the same graph using Simulink 2020I am using Simulink 2020. I want to combine many plots into the same graph with same x- axix. Actully I used ''to workspace'' command but matlab 2020 overlap the ex data array with the new one. Therefore can any one help me with that issue?AHMED I. M. ALNAHHALhttps://ww2.mathworks.cn/matlabcentral/profile/authors/20970605tag:ww2.mathworks.cn,2005:Question/7587092021-02-28T18:05:55Z2021-02-28T18:05:55ZDigital Filter-"Filter order"In Example 1, the FIR filter has a transition bandwidth of 240 Hz. Reduce the transition band of the filter to 120 Hz by changing the passband and stopband frequencies. Re-run the filter code and plot the filter. What is the filter order?
Md Mahihttps://ww2.mathworks.cn/matlabcentral/profile/authors/21432262tag:ww2.mathworks.cn,2005:Question/7584792021-02-28T11:01:37Z2021-02-28T18:00:35ZHow to extend the colon operator for my own classI am about to write an arithmetics for matlab.
Now I try to include the colon operator, i.e. to define the function colon for my class of numbers.
What do I have to do to implement the colon function? I know that the return type is a so called range
and for me as a java programmer it looks very much like an iterator,
i.e. an object allowing the functions hasnext(.) and next(.).
Please give me a hint on how to do it. Ernst Reissnerhttps://ww2.mathworks.cn/matlabcentral/profile/authors/6229746tag:ww2.mathworks.cn,2005:Question/3953242018-04-16T19:19:48Z2021-02-28T17:58:39Zhow can I replace the softmax layer with another classifier as svm in convolution networkI made deep learning application that using softmax
layers = [
imageInputLayer(varSize);
conv1;
reluLayer;
convolution2dLayer(5,32,'Padding',2,'BiasLearnRateFactor',2);
reluLayer()
maxPooling2dLayer(4,'Stride',2);
convolution2dLayer(5,32,'Padding',2,'BiasLearnRateFactor',2);
reluLayer()
maxPooling2dLayer(2,'Stride',2);
convolution2dLayer(5,64,'Padding',2,'BiasLearnRateFactor',2);
reluLayer();
maxPooling2dLayer(4,'Stride',2)
fc1;
reluLayer();
fc2;
reluLayer();
%returns a softmax layer for classification problems. The softmax layer uses the softmax activation function.
softmaxLayer()
classificationLayer()];
I want to use SVM and random forest classifiers instead of softmax. and use a deep learning for feature extraction. I hope I can get a link for a tutorial.
Suheer Alihttps://ww2.mathworks.cn/matlabcentral/profile/authors/12059052tag:ww2.mathworks.cn,2005:Question/7586342021-02-28T16:30:06Z2021-02-28T17:58:14ZHow to solve a non linear ovedetermined system of equations??Please help me how solve this, using fmincon fsolve etc I am tired of syntax errors
eq(k)=(sqrt(x1-x0)^2+(y1-y0)^2+(z1-z0)^2)==c*(t1-t0); Unknowns are x0 y0 z0 and t0, eqn(k) are 8. I am not exactly sure what tricks to unleash with the optimization algorithms in matlab. I have even tried to simplify the equation further to sqrt (a1^2+a2^2+a3^2+a4^2==c*(ti-t0)); hoping to simplify it and solve for a1 a2 a3 and a4, find the sqrt and hopefully give a good estimate for the unknowns at this point I am frustrated its not working. I have watched all the optimization videos,they make really look easy but it isnt, someone help please before I loose my mind, thanks.Alphonce Owayohttps://ww2.mathworks.cn/matlabcentral/profile/authors/13635820tag:ww2.mathworks.cn,2005:Question/7583592021-02-28T05:05:43Z2021-02-28T17:57:41ZHow should I find cubic root?How should I find roots for
5x^3-x^2+x-1=0
priya anjalihttps://ww2.mathworks.cn/matlabcentral/profile/authors/18840553tag:ww2.mathworks.cn,2005:Question/7585042021-02-28T11:36:05Z2021-02-28T17:56:35ZDeleting multiple rows based on a specific conditionHi all,
I am working on a water network. I got a big matrix 381x12527 (time vs node's quality concentration) even for times that I am not interest in. So I want to delete the matrix rows for which the difference between two consecutive rows is not equal to 3600 (see yellow rows in Figure).
I would appreciate if anyone could help me, thanks!
StefaniaStefania Avvedimentohttps://ww2.mathworks.cn/matlabcentral/profile/authors/14239001tag:ww2.mathworks.cn,2005:Question/7574692021-02-26T21:43:32Z2021-02-28T17:53:41ZThree variables (two independent) 3D plottingI want to plot B, L, and R mutually at the same time (using both 'for' loop).
clear all
clc
R=[];
for B=-20:20;
M=1;
X=M+B;l
T=[];
for L=-10:10;
N=2;
Y=N+X;
r=B+Y+L^2;
T=[T r];
end
R=[R T];
end
MOHD UWAIShttps://ww2.mathworks.cn/matlabcentral/profile/authors/15689444tag:ww2.mathworks.cn,2005:Question/7457722021-02-15T10:30:56Z2021-02-28T17:51:33ZSimulation runs fine despite error (index out of bounds)Hello.
Summary
For my simple model, Simulink (R2020b) throws an error during Model Update, but afterwards allows me to simulate (run) the model without any problems. In my understanding, an error during Model Update should make the Model Update unsuccessful and prevent me from running the simulation. The error does not occur using R2018b and R2019b. I wonder whether this is a bug.
Steps to reproduce
Create an empty model. Insert and connect the following blocks as shown in the screenshot: Integrator, MATLAB Function, Mux, Demux, Terminator. Change the code for the MATLAB Function as shown in the screenshot. Activate "Signal Dimensions" and "Non-scalar lines" in Debug --> Information Overlays --> Signals. Do not change any other default settings.
During Model Update, Simulink (R2020b) shows this error message:
The error messages argues that accessing x(2) is invalid. Despite the error, Simulink has identified the correct signal dimensions (see block diagram) and allows running a simulation without any problems.
Remarks
That is a minimal example I found to demonstrate the problem. It does not do anything useful. I know I can suppress the error by specifying the dimension ("2") of one of the ports of "fcn" or by using a Signal Specification block on either of the non-scalar signal lines. No need to tell me that. That's not my question. If Simulink finds an error, it should stop me. And if there's no problem, Simulink shouldn't throw an error. And I wonder why the behavior changed somewhere between R2019b and R2020b.
Thanks for your help!
creepydoghttps://ww2.mathworks.cn/matlabcentral/profile/authors/6715533tag:ww2.mathworks.cn,2005:Question/7586842021-02-28T17:27:52Z2021-02-28T17:49:59ZHow to suppress opening of command window?I am opening the matlab application from vba by following vba code
Public Sub StartExeWithArgument()
Application.ScreenUpdating = False
fileToRun = "C:\Users\Sandip\Desktop\exe project\mainfile"
matlabCommand = "matlab -nosplash -nodesktop -r "" run('" & fileToRun & "');warning off;exit;"" "
Shell (matlabCommand)
Application.ScreenUpdating = True
End Sub
Program is running fine, but the command windown is popping up everytime I run the program.
How to suppress opening of command window?s lahirihttps://ww2.mathworks.cn/matlabcentral/profile/authors/2110108tag:ww2.mathworks.cn,2005:Question/5294982020-05-21T20:05:02Z2021-02-28T17:49:27ZHow to extract PUBMED information?Pubmed updated and the old getpubmed function from the bioinformatics toolbox does not work. Does anyone have a solution?Arjun Watanehttps://ww2.mathworks.cn/matlabcentral/profile/authors/12909164tag:ww2.mathworks.cn,2005:Question/7570092021-02-26T13:10:06Z2021-02-28T17:48:01ZDiscretising a size distribution function and area under the curve I have some parameters for some data and I am plotting a size distribution function. The probability function I am using is given below:
Currently I have the following code which plots the function:
clear
clc
close all
mu = 0.015; % geometric mean radius
sigma = 1.6; % geometric standard deviation
Ntot = 850; % total number concentration
nbins = 200; % number of bins
rMin = (mu/(10*sigma)); % determine the minimum radius
rMax = (mu*10*sigma); % determine the maximum radius
rs = logspace(log10(rMin),log10(rMax),nbins+1); % vector containing rs
for i = 1:length(rs)
sizedist = Ntot/((sqrt(2*pi))*log(sigma))*exp(-(log(rs./mu).^2)./(2*log(sigma^2)));
end
% plot the size distribution function
semilogx(rs,sizedist,'Linewidth',2);
xlim([10e-4 10e1]);
xlabel('Particle Radius, \mum');
ylabel('Number Concentration, cm^3');
The first problem I have occurs here. Shouldn't the area under the curve be equal to the total number concentration specified? As this doesn't seem to be the case.
For the model I am coding it is necessary for the aerosol population to be discretised into bins.
Now suppose I wish to discretise this function into bins, currently the vector rs is the bin edges. I would like to know how to find the number concentration in each bin, but as stated above the area under the curve doesn't seem to equal Ntot. Can anyone see whether i'm doing anything wrong?
What I would like to do is to determine the Number Concentration in each bin, which when added together should total the value of Ntot.
Hopefully someone can help!!! Liam Holbeche-Smithhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17297908tag:ww2.mathworks.cn,2005:Question/7587042021-02-28T17:46:10Z2021-02-28T17:46:10ZSetting PeriodLimits with wcoherenceHello,
I am using MATLAB 2019a, and I have a problem with the wcoherence function. I want to restrict my model to certain periods, so I have the following:
wcoherence(x,y,seconds(8),'PeriodLimits',[seconds(30) seconds(100)])
Where x and y are my vectors, 8 is the sampling period, and I want to just look at periods between 30 and 100. I get an error:
"Error using wcoherence
Expected PhaseDisplayThreshold to be one of these types:
numeric
Instead its type was duration.
Error in wcoherence>parseinputs (line 275)
validateattributes(params.mincoherence,{'numeric'},{'scalar','>=',0,...
Error in wcoherence (line 96)
params = parseinputs(numel(x),varargin{:});"
But when I include the 'PhaseDisplayThreshold' argument with a arbirary value of 0.1, the function ignores the 'PeriodLimits' argument and reverts to displaying Frequency on the y axis. I don't want to simply trim the axis to the periods I want to display, because I don't want the periods outside of my region of interest to saturate the powers of the other periods. (Also, I should mention I've thoroughly read the help topics and have been playing around with this for some time now!)
Any help is greatly appreciated!Jakub Sliwinskihttps://ww2.mathworks.cn/matlabcentral/profile/authors/5775463tag:ww2.mathworks.cn,2005:Question/4303292018-11-16T20:11:27Z2021-02-28T17:45:07ZParsim with different modelsHow does parsim assign different models to different workers/cores?
It seems that parsim can assign the same models with different parameter to different workers/cores. Wenfeng Wanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12080356tag:ww2.mathworks.cn,2005:Question/7586892021-02-28T17:30:23Z2021-02-28T17:44:24ZSolving one equation with multiple variables Hia,
I'm trying to solve this equation: s(t) = 1/2*a*t^2 + v*t + s, for the variables a, v, and s. I am given that the distance(s(t)) from the orign at t=1/2, t=1, and t=3/2 is 7, 11, and 17 respectively. How do I solve for multiple unknown variables?Dakota Randlehttps://ww2.mathworks.cn/matlabcentral/profile/authors/21644278tag:ww2.mathworks.cn,2005:Question/7521992021-02-22T02:16:14Z2021-02-28T17:36:55ZError in @(filename)readAndPreprocessImage(filename)I am a newbie in MATLAB and deep learning. I tried
```
trainingFeatures=activations(net,trainingSet,featureLayer,'MiniBatchSize',32,'OutputAs','columns');
```
but it gave me this error:
imds.ReadFcn=
@(filename)readAndPreprocessImage(filename)
Undefined function 'readAndPreprocessImage' for input arguments of type 'char'.
Error in @(filename)readAndPreprocessImage(filename)sidra nahttps://ww2.mathworks.cn/matlabcentral/profile/authors/16153506tag:ww2.mathworks.cn,2005:Question/7586492021-02-28T16:42:06Z2021-02-28T17:36:32ZHow to find the value of X to Y = 70?Gabriel Costahttps://ww2.mathworks.cn/matlabcentral/profile/authors/16943927tag:ww2.mathworks.cn,2005:Question/7586542021-02-28T16:52:15Z2021-02-28T17:35:42ZHow do I calculate this definite integral in matlabhello. I want to calculate this integral. But it does not answer.
please check it. thanks
clc
clear
syms x
f = (124-x)^3/((12.152-2*x)^2*(1.24-x));
F = int(f, x, 0, 4.23)
Behzad Rahmanihttps://ww2.mathworks.cn/matlabcentral/profile/authors/21632399tag:ww2.mathworks.cn,2005:Question/7586942021-02-28T17:34:55Z2021-02-28T17:34:55ZDelay between two signalsI need to calculate the time between the end of a first signal and the and the end of a second signal.
It can be supposed that the two signals start at the same time.
How i can do?Palese Annamariahttps://ww2.mathworks.cn/matlabcentral/profile/authors/14443954tag:ww2.mathworks.cn,2005:Question/7586242021-02-28T16:12:56Z2021-02-28T17:34:28Zuse vector as inputI want to give each input of a vector as an argument to my function to recive a list of values that i can then plot (my goal is to plot the time it takes to execute the function for a given n). The problem is, that i only get the output of the first entry of the vector. What did I do wrong?
>> n = [1:1:10];
>> [a,b] = calcEulerSum2 (n)
it returns only calcEulerSum2(1)
function [e, a] = calcEulerSum2(n)
den = 1;
e = 1;
tic
for i = 1 : n
den = den * i;
e = e + 1/den;
end
a = toc;
endVincent Degondahttps://ww2.mathworks.cn/matlabcentral/profile/authors/21619759tag:ww2.mathworks.cn,2005:Question/7516492021-02-21T10:59:59Z2021-02-28T17:32:32ZHow to creat and plot a confusion matrix of the trained CNN netowork?I have trained a CNN and result showed down but I would need help to find the confusion matrix of the network validation accuracy outcome Mohamed Elbeialyhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11449960tag:ww2.mathworks.cn,2005:Question/7532242021-02-22T23:49:19Z2021-02-28T17:25:22Znlinfit fitting error approaching infinity I am trying to run the code below:
However I am getting the error:
Error using nlinfit>checkFunVals (line 649)
The function you provided as the MODELFUN input has returned Inf or NaN values.
Error in nlinfit>LMfit (line 620)
if funValCheck && ~isfinite(sse), checkFunVals(r); end
Error in nlinfit (line 284)
[beta,J,~,cause,fullr] = LMfit(X,yw, modelw,beta,options,verbose,maxiter);
How can I solve this issue
A(:,:,1) = [1.17 1.2 1.22 1.23 1.25 1.27
1.18 1.21 1.22 1.23 1.25 1.25
1.19 1.21 1.22 1.23 1.24 1.24
1.2 1.22 1.22 1.22 1.23 1.22
1.2 1.21 1.22 1.22 1.22 1.22
1.2 1.21 1.21 1.21 1.21 1.2
1.2 1.2 1.2 1.2 1.2 1.19];
A(:,:,2)=[ 1.22 1.26 1.31 1.33 1.37 1.39
1.26 1.29 1.32 1.33 1.36 1.37
1.27 1.3 1.32 1.33 1.36 1.36
1.28 1.31 1.33 1.34 1.35 1.34
1.29 1.31 1.32 1.33 1.34 1.33
1.29 1.3 1.31 1.32 1.32 1.31
1.29 1.3 1.31 1.31 1.31 1.29];
A(:,:,3) = [1.29 1.34 1.37 1.41 1.45 1.47
1.31 1.36 1.4 1.42 1.44 1.45
1.33 1.38 1.41 1.41 1.43 1.43
1.35 1.39 1.41 1.41 1.42 1.41
1.35 1.39 1.41 1.41 1.41 1.4
1.36 1.38 1.4 1.39 1.4 1.38
1.36 1.38 1.39 1.39 1.39 1.37];
K = 60:10:120;
C = [0 0.1 0.2 0.3 0.6 0.9];
X = [7 10 13.5].^2/100^2;
[c, k, x] = meshgrid(C, K, X);
% % % MAPPING: x = ckx(:,1), y = ckx(:,2), z = ckx(:,3), a = b(1), b= B(2), c = b(3), d = b(4)
ckx = [c(:) k(:) x(:)];
Eq = @(b,ckx) ((b(8).*ckx(:,2).*ckx(:,1)) + 1).*(b(1).*ckx(:,2) + b(2).*(ckx(:,1)).^b(3)).* ckx(:,3).^(b(4).*ckx(:,2)+b(5).*(ckx(:,1)+1).^b(6)) + b(7);
B = nlinfit(ckx, A(:), Eq, [0.01, 1, 1, 0.01, 0.1, 0.1, 0.1, 0.00001]);
plot(A(:)); hold on; plot(A(:)-R)
xticks([4:7:126])
xticklabels([0 0.1 0.2 0.3 0.6 0.9 0 0.1 0.2 0.3 0.6 0.9 0 0.1 0.2 0.3 0.6 0.9])
Muhannad Fadhelhttps://ww2.mathworks.cn/matlabcentral/profile/authors/19879888tag:ww2.mathworks.cn,2005:Question/7586792021-02-28T17:23:55Z2021-02-28T17:23:55ZFast Restart in Response Optimization ToolI'm trying to use the Fast Restart option in the Response Optimization tool with my Simscape model, (I'm doing a "signal tracking" scenario). Specifically I'm using a thermal nodal model in Simscape (thermal resistors, capacitors, temperature sources, convective loads, and heat sources). I define these parameters in a separate Matlab .m file and run it prior to running the Simscape model. The response optimization will run when I do not use fast restart, but it takes an incredibly long time because it is compiling the model each and every iteration. When I try to use the fast restart mode, it says "these parameters (parameter names) cannot be modified while the model is in FastRestart. Either do not modify these parameters or run the model in normal mode". Is this a limitation of the program or could I be doing something wrong. I'm trying to tune values of thermal resistances, capacitances, and heat values.Adam Whelanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/21671029tag:ww2.mathworks.cn,2005:Question/7586742021-02-28T17:20:57Z2021-02-28T17:20:57ZSave multiple image automaticallyHi, I'm a final year student at a university in Indonesia. Actually I tried reading the image in matlab and then applying certain operations like increasing contrast, removing background etc. Then I want to save the new image after the operation in a certain folder, but I face a problem in saving the image in matlab, the image is saved after only one operation while the image that has been read is more than one, then I want the saved image extension to be .jpg. please help me whoever knows the solution.
This is the coode:
image_folder = 'F:\kuliah\semester6\TA2\mencoba';
outfolder = 'F:\kuliah\semester6\TA2\mencoba\hasil';
if ~isdir(outfolder); mkdir(outfolder); end
load mri %I presume it has the variable map in it
files = dir(fullfile(image_folder, '*.jpg'));
% filenames = fullfile({fileinfo.folder}, {fileinfo.name});
% total_images = numel(filenames);
for iFiles = 1:numel(files)
thisfilename = fullfile(files(iFiles).folder,files(iFiles).name);
% for n = 1 : total_images
% thisfile = filenames{n};
[~, basename, ext] = fileparts(image_folder);
citra = imread(thisfilename);
V = squeeze(citra);
fprintf('processing %s\n', basename);
fig = figure;
citra3 = montage(reshape(V,size(citra)), map, 'Indices', 3);
outfile = fullfile(outfolder, sprintf(['%s-coba-%03d.%s',basename,'.jpg']));
saveas(citra3, outfile);
endFrisda Sianiparhttps://ww2.mathworks.cn/matlabcentral/profile/authors/21534709tag:ww2.mathworks.cn,2005:Question/7567742021-02-26T08:41:53Z2021-02-28T17:19:49ZSurf plot as .svg file with many grid lines too darkHi Matlab-Community,
I want to insert a surf plot into my thesis latex document with about 60x85 data points. Tikz creates too large files and runs into problems - so that is not an option.
A nice (time-consuming) alternative is to export the plot as .svg, open it in inkscape, add all text and tiks manually and save as pdf_tex. That way, I get a nice vector graphic with document compatible text without matlab2tikz. At least I thought...
Here is my problem:
The plot is too dark due to the many edge lines. Redrawing fewer edges with plot3 does not work for the "60"-direction, since I want to keep the bounding edge lines and even spacing (59 is a prime number and cannot be divided evenly). It seems, that I can't change the linewidth of the full 60x85 plot3 redrawn edges, to decrease the darkening effect. I guess I could compute intermediate edge values between my given data points with (bi-)splines or linear interpolation, but there must be another way. Redoing the simulation on which the surface is based is overkill and takes too long.
Illuminating the plot with a light feature is not an option, since I need the Painters renderer for the .svg export and the two of them are not compatible. Brightening with briten does work but not well enough.
Is there anything, that I'm missing? Do you have any suggestions? Thank you so much in advance!
Simon Bäuerlehttps://ww2.mathworks.cn/matlabcentral/profile/authors/12178072tag:ww2.mathworks.cn,2005:Question/7532292021-02-23T00:28:59Z2021-02-28T17:18:08Z“Matlab Forever!" (Audio Signal Processing Project)Broad Aim: When did someone say something on a TV program?
Viewers of a TV program (e.g. game show contestants answering timed questions) believe they are watching the same content at the same time as other viewers across the country. But due to transmission delays, they are actually watching a given part of the program seconds or minutes apart. This time difference between the original source material (audio reference file) and the viewed material (the user’s audio file) is what I am trying to determine using Matlab.
The Application: Using a phone, a user points their phone to the sound coming from a TV in a normal living room where there would be extraneous noises apart from the sound (program content) coming from the TV. The user records a sample of a few seconds at the beginning of the program. This captured sound sample is transmitted back to the server where it is compared against a reference audio file of the same content. The aim is to determine exactly where the viewer is up to in the TV program timeline.
Example
Stage 1: Each user is invited to grab a sound sample of a few seconds of the program material at the very beginning of the program. This is relayed back to the server as the user's initial program time.
Stage 2: At 5 minutes, 32 seconds from the beginning of the program (an arbitrary start point) the actor raises his hand and declares "Matlab Forever!".
User 1: Views this scene at 00:05:34 and acknowledges this cue by tapping a button on his phone UI.
User 2: Views this scene at 00:05:36, ditto
User 3: Views this scene at 00:05:42, ditto
The system now knows that users 1, 2, and 3 have delays of +2, +4, and +10 seconds respectively from when the material was broadcast. Mission accomplished.
Advice Sought
1) What is the level of difficulty of this project for someone who is not an engineer, does not have a mathematical background, no programming experience? I have never used Matlab before. Will download a trial shortly. That said, I do have some experience with audio, music, sound processing.
2) It's hard for me to gauge the feasibility of being able to pull this off. No doubt the community can help with the occasional problem, which is great, but I imagine there will be parts of the project where I need direct help. I am happy to pay for a few hours here and there, as that would seem fair. (Not sure if the community rules allow this) Anyone interested on that basis?
3) Can this project be done with these three Matlab tools? Signal Processing Toolbox, Signal Analyzer, Audio Toolbox. Perhaps Simulink too?
4) To kickstart this, any methodology tips would be great appreciated.
Thanks!Pete Mhttps://ww2.mathworks.cn/matlabcentral/profile/authors/20974590tag:ww2.mathworks.cn,2005:Question/7586642021-02-28T17:14:28Z2021-02-28T17:16:19ZWhile loop in if and for loopHi all,
I am trying to combine a while loop in an if and for loop but I am having some problems with the results of my matlab code.
I am trying to recognize in a for and if loop wether a variable is true and as long as this variable is true I want it to execute a part of the code. As soon as this condition is not true, I want my code to go back to the for loop, with the new value of i. Here is an example of my code:
for i = 2:N
if Gyr_2(i,3) ~= 0 % Checks wether this condition is true for the value of i
[Output] = RBK2(Input); % Self created function
elseif Gyr_2(i,1) ~= 0 || Gyr_2(i,2) ~= 0 || Ori_2(i,1) ~= 0 || Ori_2(i,2) ~= 0 % Checks wether this condition is true for the value of i
[Output] = RBS2(Input); % Self created function
elseif Acc_2(i,3) ~= 0 % Checks wether this condition is true for the value of i
[Output] = RBH2(Input); % Self created function
else % If none of the conditions are true
[Output] = RBL2(Input); % Self created function
if Diagonal5(i) == 1 && Acc_3(i,1) ~= 0 && Acc_3(i,2) ~= 0 % Checks again if this condition is true
if abs(Vel_3(i-1,1)) > abs(Vel_3(i-1,2)) && Acc_2(i,2) ~= 0
while Diagonal5(i) == 1 %Value is either 1 or 0
[Output] = RBD2x(Input) % Self created function
i = i + 1;
end
else
while Diagonal5(i) == 1 && Acc_2(i,1) ~= 0
[Output] = RBD2y(Input) % Self created function
i = i + 1;
end
end
end
end
end
So basically, when it does the "while Diagonal5(i) == 1" I want the code to stay within this loop until Diagonal5(i) == 0. However it seems like it always jumps out of the while loop and goes back to the beginning of the for loop with the next value of i, instead of using the value of i when Diagonal5(i)==0. I have also done it without writing the "i = i+1;", but then when I start my code, it does not complete and takes a really long time to load.
Could you guys please tell me how i can fix that. I have read multiple different answers but have not found one that works for me. Should I otherwise write my code differently to solve this problem?
Thanks in advance
Sam :)Samuel Bofferdinghttps://ww2.mathworks.cn/matlabcentral/profile/authors/17955016tag:ww2.mathworks.cn,2005:Question/7574792021-02-26T21:51:09Z2021-02-28T17:14:32ZHow can I get randperm to return a permutation of a vector that has no entries at their original positions?I want take a random permutation of a vector such that all entries of the vector move to a new location.
For example, if I have a vector [1,2,3,4,5], then the following permutations are acceptable:
[2,1,4,5,3], [3,1,5,2,4], [5,4,2,3,1], etc.
However, for me, the following vector is not acceptable:
[2,4,3,5,1]
because the "3" has remained in the same location.
The "randperm" function in MATLAB allows for some of the entries in the vector to stay in the same position. Is there some way to use randperm that stops it from doing this? Or is there some other function out there that I am missing? (I have also looked at the functions "datasample" and "randsample" but they also do not seem to allow for this).Darcy Cordellhttps://ww2.mathworks.cn/matlabcentral/profile/authors/6864376tag:ww2.mathworks.cn,2005:Question/7584592021-02-28T10:34:35Z2021-02-28T17:10:18Zcreating a coundown alarm everytime a function have been askedHello, basically what I want to do is that i want to create a simple function like this:
function [] = alarm()
print("5 seconds to wake up")
end
and everytime i call the function without giving it any initial parameter i want the countdown to decrement so the first time i call it: alarm() return: 5 seconds to wake up
second time: alarm() return 4 seconds to wake up
etc... to reach 0
how can i do that ?Mouhamad Ibrahimhttps://ww2.mathworks.cn/matlabcentral/profile/authors/20835196tag:ww2.mathworks.cn,2005:Question/7583292021-02-28T02:31:54Z2021-02-28T17:09:38ZInvalid Simulink object name: loader &&& xPC：unable to load dependent module FAST_Library_Win32.dll @ MathWorks Support TeamDiagnosic Viewer：
The call to slrt_make_rtw_hook, during the exit hook generated the following error: Invalid Simulink object name: loader The build process will terminate as a result.
Caused by:
Invalid Simulink object name: loader
No block diagram 'loader' is loaded.
xPC：
unpacking application...
unpacking appplication finished
unable to load dependent module FAST_Library_Win32.dll
Loading H:\private\CFDLMFAC.dlm failed with error 2
Error: Could not laod model H:\private\CFDLMFAC: 2
jianshen lihttps://ww2.mathworks.cn/matlabcentral/profile/authors/8704196tag:ww2.mathworks.cn,2005:Question/7586592021-02-28T17:07:11Z2021-02-28T17:07:11ZMatlab Logit regression scatterplot has overlapped outcomes? Dear Mathworks community,
I used the Pima Indians Diabetes dataset with just 2 variables to predict the probability of having diabetes or not. I removed 0 values (as they are missing values) for both predictors. When I ran decision boundary on the scatterplot it looks like this, training accuracy is still 75% should I be worried something is wrong? I do not have options to choose another algorithm since LR was what I learnt in class. Thank you very much.Khanh Ha Tranhttps://ww2.mathworks.cn/matlabcentral/profile/authors/20670402tag:ww2.mathworks.cn,2005:Question/7586442021-02-28T16:40:19Z2021-02-28T17:06:36ZHow do you create a composite function in matlab?If I have two functions, like
function a=func1(x)
and
function b=func2(q,p)
as examples. Is it possible to combine them to create a composite function like func1(func2(q)) = func1∘func2(q), and if so how do you do that? Buttercup12https://ww2.mathworks.cn/matlabcentral/profile/authors/20964958