https://in.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-08-22T16:46:24Ztag:in.mathworks.com,2005:Question/4771372019-08-22T06:30:01Z2019-08-22T16:46:24ZHow to extract tweets given an IDHi
I am currently working on a project which demands analysing tweet data. For this, I have dopwnloaded a dataset which supposeldy containing the tweets as well as the category assigned against each tweet. However, after downloading the dataset I found it conatins some ID's and the assigned category. I have attached a snapshot of the dataset following:
Until now, I have tried this following sample code:
baseurl = 'https://api.twitter.com/1.1/statuses/show.json';
parameters.count = 1;
d = getdata(c,baseurl,parameters,'id','567824878201511000');
which shows error after execution. The error is following:
Error using char
Conversion to char from struct is not possible.
Error in twitter/getdata (line 73)
requestParams.(char(varargin{i})) = varargin{i+1};
Error in tweetRetreat (line 60)
d = getdata(c,baseurl,parameters,'id','567824878201511000');
I am pretty doubtdul how to extract tweets against each number from the dataset after creating the twitter credentials. Does anyone of you advice me in this regard?
thanks, Saugata Bosehttps://in.mathworks.com/matlabcentral/profile/authors/13294360-saugata-bosetag:in.mathworks.com,2005:Question/4770982019-08-21T22:07:07Z2019-08-22T16:43:08ZGet a matrix by interaction Hello good day.
A synthesis of the code or pseudocode is shown.
____________________________________
clc; clear; close all; short format
Ccl = 21; % Number of lines
gen = 1; % Number of times the code is repeated in each generation (gen)
for wl = 1: gen
for kk = 1: Ccl
PROCESS
Obtaining the values of:
dx1, dy1, dx2, dy2, dx3, dy3, SLL
end
BCG = horzcat (dx1, dy1, dx2, dy2, dx3, dy3, SLL);
[minimum, row] = min (BCG (:, end));
generate = BCG (row, 1: end-1)
m (wl) = minimum
end
_________________________________________________________
In the result I get a matrix ("BCG") of size 21 X 7 With the variable "gen = 1"
Giving the value of 3 to the variable "gen" gives me a matrix ("BCG") of 21 X 21
that is to say it shows me a matrix with 3 times each of the variables
What do I have to do to obtain a matrix ("BCG") of 21 X 7 in each generation (gen) and that in each generation (gen) the corresponding matrix ("BCG") is saved?
Greetings.Ricardo Gutierrezhttps://in.mathworks.com/matlabcentral/profile/authors/8586559-ricardo-gutierreztag:in.mathworks.com,2005:Question/4771322019-08-22T05:44:30Z2019-08-22T16:41:55ZIn which dimensions we want to use in simulink for minidrone competitionFor designing a path way which dimensions want to used for MATLAB minidrone competitionNaveen Lhttps://in.mathworks.com/matlabcentral/profile/authors/15737637-naveen-ltag:in.mathworks.com,2005:Question/4772242019-08-22T16:41:53Z2019-08-22T16:41:53ZCan you import a label map from slicer (file type .nrrd) into matlab as a point cloud?I want to display a label map I have segmented in Slicer in a matlab figure, I am not very experienced working with point clouds and was hoping this might be possible?Student123https://in.mathworks.com/matlabcentral/profile/authors/14074492-student123tag:in.mathworks.com,2005:Question/4772122019-08-22T14:30:22Z2019-08-22T16:41:11ZHow to extract data from a multi layered structureHi,
I have a multi-layered structure A that include 3 structures (a, b and c) and and all of them contain 10 fieldnames with 10 rows and every cell further contains 10 double numbers mixed with nans.
Doing
A.b.fieldname1
yields the content of the first cell (10 double), but I cant seem to to be able to extract the entire fielname. Doing
c = cell2mat(struct2cell(A.b.fieldname1(1,1)))
yields the following error: Expected one output from a curly brace or dot indexing expression, but there were 10 results.
So how can I extract the data from this multi-layered structure ?
Thank you,Blueginhttps://in.mathworks.com/matlabcentral/profile/authors/8172945-bluegintag:in.mathworks.com,2005:Question/4772222019-08-22T16:21:20Z2019-08-22T16:40:26ZCopy a figure to a subplot including all elementsI have a moderately complex plot that I produce regularly, for various purposes, and I have therefore put generation of that plot into a function.
I now have an application where I need to show a grid of these plots - so I need to take the figure produced by the function and put it into a subplot.
The closest approach to this that I've found so far, from some googling, is,
copyobj(allchild(get(figurehandle, 'CurrentAxes')), subplotaxeshandle);
This serves to copy the actual graph, but omits axis labels, title, etc., as they are not children of the axes. It's worse if it's a polar plot, as it also doesn't bring across axis properties like ThetaDir or ThetaZeroLocation.
I guess that I could probably work out how to find the handles for those things and copy them manually, like above, but that loses much of the benefit of abstracting the figure production to a function in the first place. Surely there must be a better way?
ThanksSimonhttps://in.mathworks.com/matlabcentral/profile/authors/2971551-simontag:in.mathworks.com,2005:Question/4772192019-08-22T15:55:01Z2019-08-22T16:38:25ZTroubles using built-in volumeViewer() app?I am converting a series of dicom slices into a single nifti image. To do this I am using a popular software downloaded from the internet, spm12. My goal is to convert the dicom files to the nii format then view them in some image viewer( either Amide, volumeViewer(), etc) to make sure that there raw data matrix has the same orientation and position in space regardless of coordinate system change or any transformations applied to either the nii or dicom files. In order to do this I must know, with certainty, 2 things about the behavior of niftiread,dicomread and volumeViewer:
1. Do niftiread and dicomread return the raw data present in the image OR do they apply any coordinate flip with any transformation then return the raw data?
2. Same goes for volumeViewer(), does it just take in a data matrix from dicomread or niftiread then display it exactly as it is? Or does it know that this data matrix is a nii or dicom image then flip the axis's or apply a transform to it?
I have read the descriptions and parsed through the code of the functions themselves, but having clarity about the behavior of these functions would greatly increase my debugging process.
Any help is greatly appreciated and feel free to comment with questions if this is either wordy and confusing or not descriptive enough.
EDIT: As of right now I'm viewing a dicom image in the volumeViewer() that is 90 degrees rotated and left right flipped compared to the nii image. The left right flip makes sense, the 90 does not. Bryce Johnsonhttps://in.mathworks.com/matlabcentral/profile/authors/12423196-bryce-johnsontag:in.mathworks.com,2005:Question/4770932019-08-21T20:49:24Z2019-08-22T16:37:23ZMaking a contour plot with 1-D z values?I have experiemntal splash data with X being the Weber number Y being the Reynolds number and Z being a number (1-5) depending on the splash pattern. I am trying to vissulize this data by using a contour plot but cannot figure out to format my code since my Z is not a matrix. I have attached my data and any help would be greatly appreciated. I have been able to create the contour plot attached but I need smooth lines and only integers in the legend. I would like my plot to look like similar to the screen shot uploaded. Bailey Bassohttps://in.mathworks.com/matlabcentral/profile/authors/6857709-bailey-bassotag:in.mathworks.com,2005:Question/4770862019-08-21T19:22:00Z2019-08-22T16:34:58Zisprime function seems to have poor performanceWhy is MatLab's "isprime" function so much slower than Octave's "isprime" function?
I am using MatLab's "isprime" function to check whether a large number is a prime or not using the symbolic toolbox. I found that the performance of "isprime" in MatLab is much slower than in Octave. Why is this the case or what am I doing wrong with MatLab?
My tests with octave testing large Mersenne-primes produced the following runtimes for "isprime":
tested prime runtime in seconds
2^607-1, 0.15724
2^1279-1, 0.18309
2^2203-1, 0.41784
2^2281-1, 0.70215
2^3217-1, 1.7013
2^4253-1, 2.4854
2^4423-1, 2.2523
2^9689-1, 25.7571
2^9941-1, 25.761
2^11213-1, 38.3376
and with MatLab's "isprime":
tested prime runtime in seconds
2^607-1 31.930225
2^1279-1 547.414940
2^2203-1 5168.567632
2^2281-1 5578.169207
2^3217-1 461.535261
2^4253-1 739.918345
2^4423-1 3805.209681
2^9689-1 8954.457005
2^9941-1 10550.740359
2^11213-1 11865.530147
MatLab's documentation about "isprime" says, that 10 random tests based on the Miller-Rabin method are done. I believe, Octave only does 4 random tests (I suppose also Miller-Rabin, but I am not sure). However this does by far not explain the huge difference in runtime.
In both cases no parallelisation was used and the program ran on one thread on the CPU.
This is the MatLab code I used to run the test. The Octave version is basically the same...
function speedtrace_isprime();
% teste Dauer der Ausführung von "isprime" in Abhängigkeit von wachsenden Mersenne-Primzahlen 2^p-1
% zu testende p's:
p = [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433, ...
1257787, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583, 25964951, 30402457, 32582657, ...
37156667, 42643801, 43112609, 57885161, 74207281, 77232917, 82589933];
speedtrace = fopen('speedtrace_isprime.txt', 'w'); %trace-file öffnen
fprintf(speedtrace, "%s %s \n", "Start: ", string(datetime)); % schreiben
fprintf(speedtrace, "%s \n", "getestete Primzahl, Zeit in Sekunden, Uhrzeit/Datum"); % schreiben
fclose(speedtrace); % file wieder zumachen
base = sym("2");
disp(["getestete Primzahl, Zeit in Sekunden, Uhrzeit/Datum"]);
for k = 1:1:numel(p);
tic;
isprime(base^p(k)-1);
Zeit(k) = toc;
fprintf("2^%i-1 %f %s \n", p(k), Zeit(k), datetime);
speedtrace = fopen('speedtrace_isprime.txt', 'a');
fprintf(speedtrace,"2^%i-1 %f %s \n", p(k), Zeit(k), datetime);
fclose(speedtrace);
% figure(1); plot(Zeit);
end;
speedtrace = fopen('speedtrace_isprime.txt', 'a');
fprintf(speedtrace, "%s %s \n", ["Ende: ", string(datetime)]);
fclose(speedtrace);
end
Thomashttps://in.mathworks.com/matlabcentral/profile/authors/15773293-thomastag:in.mathworks.com,2005:Question/4772172019-08-22T15:26:30Z2019-08-22T16:26:54ZRemoving invalid results knowing the trendHello,
I have a matrix, which is an output from angle measurement from a motor. So, over time the angle increases over time until it reaches a maximum (360 i.e) and then stops or descreases.
. For instance:
[0 10 -1 40 50 0 60 10 90 0 ]
How can I remove the invalid values, that in that example are the -1 , second and third '0's and the second 10 ?
Thank you
marco esteveshttps://in.mathworks.com/matlabcentral/profile/authors/4736139-marco-estevestag:in.mathworks.com,2005:Question/4771232019-08-22T04:29:21Z2019-08-22T16:17:11ZHow to find the nearest voxel of a 3D image based on some specific intensity value...So I want to replace the abnormal intensity values from a 3D image. If the intensity is >1800 then I will replace it with nearest voxel value less than 1800.
I believe I can do it with hard coding... but is there any function to do that simply??Rana Banikhttps://in.mathworks.com/matlabcentral/profile/authors/13560559-rana-baniktag:in.mathworks.com,2005:Question/4770872019-08-21T19:34:40Z2019-08-22T16:15:11ZI need turnover for last month from my table Hello, I have a table like the one below:
summary =
6×2 table
Time Monthly_Turnover
___________________ _______________
'start' 0
'01-Jul-2019 17:00:39' 76
'24-Jul-2019 14:00:18' 56
'01-Aug-2019 16:00:35' 76
'15-Aug-2019 15:40:24' 98
'21-Aug-2019 13:50:01' 10
I need to get the sum of the Monthly_Turnover-column for a full month based on the timestamp in the first column (from today*). If the timestamp-column does only represent, say, two weeks, I only need the sum of those two weeks.
*) the timeformat is the same at the following line of code:
datestr(datetime('now'))
ans =
'21-Aug-2019 21:22:58'
In this case the result should be: 56+76+98+10 = 240
Does anyone have an idea how to proceed with such a problem? Thanks in advanceMartinhttps://in.mathworks.com/matlabcentral/profile/authors/4265483-martintag:in.mathworks.com,2005:Question/4772212019-08-22T15:58:09Z2019-08-22T16:07:49ZError after moving function .m file: 'Previously accessible file "...\z_estimate.m" is now inaccessible'Having created a function file "z_estimate.m" and successfully called the function (from the command line), I noticed I had inadvertently saved the file in the top-level MATLAB folder instead of the subfolder "my_functions", which is also on my Matlab path. So, I dragged the .m file from the top level into the subfolder, in the Matlab filemanager window. Now when I call that function I get the error
Previously accessible file
"...\MATLAB\zestim.m"
is now inaccessible.
In an attempt to diagnose the issue, I used "Save as..." to save a copy of the function as "z_estimate2.m" (and changed the function name to "z_estimate2"). When I call z_estimate2, it works. But I don't want my function to be called that if possible, and in future I don't want to have to rename functions if I move them.
I tried using "restoredefaultpath" from the command line and then re-adding "my_functions" to the path, but the original function won't run. If I move it back to "MATLAB" it works fine, however, I don't want all my functions in the top-level folder, I would like to be able to organise them into subfolders.
For information, I am running Windows 7. I found another question about this error, to which the answer referred to changing system TEMP variable, so mine is:
%USERPROFILE%\AppData\Local\Temp
How can I move a function file between two folders that are both on the Matlab path and still be able to call them?Tom Hortonhttps://in.mathworks.com/matlabcentral/profile/authors/15401894-tom-hortontag:in.mathworks.com,2005:Question/4772202019-08-22T15:55:09Z2019-08-22T15:55:09ZI need to locate an installed program in MacOS using Matlab, how can I do that?I need to locate an installed program in MacOS using Matlab, how can I do that?
My Matlab code needs to make sure a certain 3rd party program is installed on the computer running the matlab code.
I have a way to do it on Windows ('WHERE /F /R "C:\Users\...'), but how can I do it in Matlab?Mårten Cronanderhttps://in.mathworks.com/matlabcentral/profile/authors/8687008-marten-cronandertag:in.mathworks.com,2005:Question/4772182019-08-22T15:40:15Z2019-08-22T15:40:15Zfsolve found wrong solution for easy equationDear everyone, I have a stupid problem with fsolve:
my equation is :
wehre a and b are constante. I would like to solve it for z=linspace (0,20,100) (for exemple)
if z=0, the solution is x=1.
i write :
close all
clc
clear all
c=3e8;
r=30e-6;
Aeff=pi.*r.*r;
lambda0=1030e-9;
om0=2.*pi.*c./lambda0;
C0=0.;
eta=4E-1
b2=-4e-28;
b2=b2;
b3=1.5e-40;
g=sign(b2);
T0=100./om0;
Tr=10./om0;
n2=1e-23;
gamma=2.*pi.*n2./(lambda0.*Aeff);
a=8.*b3.*Tr./(15.*T0.^4);
b= 2.*eta.*b3./(3.*gamma.*T0.^2);
sol= fsolve(@(x) x*x-1+a/b*log( (b*x*x -a) / (b-a) ),0)
return
%%% I also try with solve
syms u
eqn = u.*u-1+a./b.*log( (b.*u.*u -a) ./ (b-a) )==0;% + 2b.*z
solu = solve(eqn,u)
Solution for z=0 is not found...
Why?
ThanksMartinMhttps://in.mathworks.com/matlabcentral/profile/authors/4816064-martinmtag:in.mathworks.com,2005:Question/4767122019-08-19T15:17:45Z2019-08-22T15:35:35ZHow can I find a Pareto optimal using weighted sum method in Multi objective optimization ? Hi All,
I am new to the MOOP problem. I would like to find out pareto optimal front using weighted sum method. So I tried the following code,
objective1=x3+y2;
objective2=y2-4x;
x0=[1,1];
w1=linspace(0,1,N);
w2=1-w1;
sol=nan(3,N);
for i=1:N
FWS=@(x) w1(i)* (x).^3 +(y).^2 + w2(i)* (y).^2 - 4x;
%sol(:,i)=fminunc(FWS,x0(:));
[x,fval] = fminunc(FWS,x0);
end
Finally I got the error like,
Error using fminunc (line 368)
Supplied objective function must return a scalar value.
Can anyone help me to clear this problem really appreciated?
Thanks
Mathihttps://in.mathworks.com/matlabcentral/profile/authors/12174130-mathitag:in.mathworks.com,2005:Question/4770072019-08-21T11:00:26Z2019-08-22T15:34:52ZFunction 'getdata' from the Image Acquisition Toolbox very slowHello,
I am using the function 'getdata' from the Image Acquisition Toolbox in a project. However, the data transfer speed is about 1.5 GB/s. It is my understanding that the data are logged in a Buffer localized on the CPU RAM. Hence, when using 'getadata' to bring the data to the CPU RAM as a variable, the speed should live up to the RAM speed - in my case 21,3 GB/s.
How can I increase this speed?
Any help will be appreciated, please.
ThanksTutuhttps://in.mathworks.com/matlabcentral/profile/authors/15418592-tututag:in.mathworks.com,2005:Question/4767192019-08-19T15:52:51Z2019-08-22T15:32:52ZLinear programming and cash flow matching I am trying to solve a simple large scale linear /non-linear programming problem to match liability cash flows with asset cash flows. I am thinking between MATLAB and R to solve this problem. I have explained the problem below and I was wondering whether MATLAB can be used to solve this.
Can anyone please let me know if and how MATLAB can be used to solve this problem? If any particular MATLAB optimization toolboxes will be needed then please let me know.
A fixed set of liability cash flows are given, say for the next 20 years. We need to select appropriate bonds to match these liability cash flows, ignoring interest rate risk and other market risks.
We are given market value of bonds and their cash flows based on which we need to decide which bonds to select.
The objective function is to minimise value of liabilities, which is calculated by discounting liability cash flows at a flat discount rate, say 1% + a spread. This spread depends upon internal rate of return of the assets portfolio, e.g. spread = 50% of internal rate of return on the asset portfolio (the higher the spread, the lower the value of liabilities.
Constraints are: weights of bonds can be either zero or 1 (i.e. either we invest in a bond or we don’t) and asset cash flows can be lower than liability cash flows in certain years but cumulatively say at every 3 years asset cash flows should exceed liability cash flows.L Smithhttps://in.mathworks.com/matlabcentral/profile/authors/15981591-l-smithtag:in.mathworks.com,2005:Question/4768542019-08-20T12:38:34Z2019-08-22T15:30:00Zhow to plot objective function with variablesxo=[0.0011,0.0049,0.3]; % assumptions
%[Q]=heatload1_new(xo)
%nvars=3;
A=[];
b=[];
Aeq=[];
beq=[];
lb=[0.001,0.002,0.01]; %lower bound
ub=[0.01,0.08,0.5]; %upper bound
nonlincon = @(x)constraint_new(x); % calling constraint function
Fitnessfun = @(x)weight_testvariable(x); %calling objective function
options = optimoptions(@fmincon,'Display','iter-detailed','Algorithm','sqp','MaxIterations',1500)
options = optimset('Display','iter','TolFun',1e-5)
[X,fval]=fmincon(Fitnessfun,xo,[],[],[],[],lb,ub,nonlincon,options)RAHUL KUMARhttps://in.mathworks.com/matlabcentral/profile/authors/15419640-rahul-kumartag:in.mathworks.com,2005:Question/4771002019-08-21T22:20:36Z2019-08-22T15:23:12Zwhy ga generates different fval and penalty valuesHello everyone, I have a question when I check the result after i using GA on my integer (binary) minimization problem that the generated fval and penalty value are not the same. Even when i tried to type like myfun(x), the result of that differs from fval and penalty value.
Also, for the penalty value, I am not sure why GA generates that because all my constraints are linear.
Thank you!BOWEN LIhttps://in.mathworks.com/matlabcentral/profile/authors/11608268-bowen-litag:in.mathworks.com,2005:Question/4772162019-08-22T15:21:46Z2019-08-22T15:21:46ZHelp on txt fileHello,
I am pretty new to Matlab, so excuse my bad understanding of its natural behaviour... :D
I want to create a txt file from my workspace, so I tried:
A = [38;70;102;134;166];
B = [10];
C =[10];
D = [0];
Variablen = {'A =', 'B =', 'Umdrehungen =', 'C =', 'D = '};
Variablen_wert = [A;
B;
C;
D;];
log(2,:) = str2cell(Variablen_wert);
log(1,:) = Variablen;
fid = fopen('temp.txt','wt');
fprintf(fid,'%-4s %d\n',log{:});
fclose(fid);
The obvious problem is, A is a matrix, while the other Variables dont have the same size. I tried to convert them into a string, but that doesnt work as well.
In the end it hopefully should look like this:
A = 38 70 102 134 166
B = 10
C = 10
D = 0
Maybe you can help me on this :) thank you very muchI3JMhttps://in.mathworks.com/matlabcentral/profile/authors/11296314-i3jmtag:in.mathworks.com,2005:Question/4767492019-08-19T20:23:18Z2019-08-22T15:21:23Znonlinear fit of experimental data Dear MatLab Experts,
I would like to generate a nonlinear regression model to fit my experimental data 'Mk_Superf_FSF' as function of the independent variables 'MaxFDiam' and 'MinFDiam' which are respectively the max and min diameter of an arbirarily shaped closed and connected 2D surface. I also added the variable 'Area' which is obviously correlated to max and min diameters so I think it is not wise to use that as well.
I was suggested a linear fit for the experimental data (see attached picture). The 7th order polynomial p(x) fits the data very well but the suggested formula is non physical. In fact, the variable used is a sum of quantities with different units:
x = MaxFDiam * MinFDiam + Area / MaxFDiam + Area / MinFDiam + MaxFDiam / MinFDiam
I cannot assign a units to ithe resulting sum because the product of the two diameters has units [mm^2.] whereas the Area/MaxDIameter has units [mm], the ratio of the two diamters is unitless.
I tried to fit a sum of two negative exponentials where in the exponent I have the Area ad the product of the diameters respectively. MatLab complained printing out that the Jacobian has a column of all zeros. I tried some other combinations of exponential functions. Again MatLab complained stating that the model returns "NaN" of "Infinity".
Some other times MatLab printed out that that maximum number of iterations had been exceeded.
I tried a power-law fit as follows:
coeffs0 = [0.8672 1 1]
opts = statset('fitnlm');
opts.RobustWgtFcn = 'bisquare';
X = [MaxFDiam' MinFDiam'];
mdlfun = @(coeff, X) coeff(1)* X(:,1).*X(:,2).^coeff(2) + coeff(3);
mdl = fitnlm(X,Mk_Superf_FSF',mdlfun, coeffs0,'Options', opts, 'CoefficientNames', {'a' , 'b', 'c'});
This time MatLab did not complain but the resulting model is anything but good. The R^2 value is awful. The P_values are very high except for one.
mdl =
Nonlinear regression model:
y ~ a*x1*x2^b + c
Estimated Coefficients:
Estimate SE tStat pValue
________ ________ ________ __________
a 0.007407 0.02121 0.34922 0.73352
b -0.26657 0.87603 -0.30429 0.76658
c 0.93603 0.048648 19.241 8.0919e-10
Number of observations: 14, Error degrees of freedom: 11
Root Mean Squared Error: 0.0363
R-Squared: 0.215, Adjusted R-Squared 0.0721
F-statistic vs. constant model: 1.51, p-value = 0.264
Maybe the model is not right. Maybe the initial parameter values are not good.....
I would greatly appreciate some help at getting a decent fit. Above all, I would like to learn techniques to:
(1) devise the model formula
(2) choose the initial parameter values
Thank you so much for any suggestion and help.
Best regards,
Maura E. M.
Maura Monvillehttps://in.mathworks.com/matlabcentral/profile/authors/13231254-maura-monvilletag:in.mathworks.com,2005:Question/4772152019-08-22T15:06:09Z2019-08-22T15:16:30ZMatch color of images by common areasI've a batch of images made by different sensors, and now I want to adjust the color so that they look similar/identical. The idea is based on the color matching with a reference chart (Macbeth chart)
The image show roughly the same areas and are already aligned. Now I want to match all color by common areas.
How can I achieve that?
What I achieved already:
Extract rgb color from each common area in all images
Transform in linear LAB / HSV colorspace
How can I estimate the transformation function to match the color?
canadarunnerhttps://in.mathworks.com/matlabcentral/profile/authors/5115785-canadarunnertag:in.mathworks.com,2005:Question/4772012019-08-22T13:09:55Z2019-08-22T15:02:55ZSection headers are formatting as comments: how to get SH working again?My section headers are formatting as comments. I was editing my code and was commenting out a block. I entered "%}" in first, and it didn't comment out when I wrote the %{ above it. Since then, my section headers are not functioning. The SH have default color settings and I can't run individual sections either. Does someone know what I messed up?
Samuel Veithhttps://in.mathworks.com/matlabcentral/profile/authors/11852481-samuel-veithtag:in.mathworks.com,2005:Question/4772142019-08-22T14:59:28Z2019-08-22T14:59:28ZHow to compile gtcc.m?!I have code that extracts a number of features, including gammatone cepstral coefficients using the matlab function gtcc. This section is currently too slow for my application, so I'm trying to find ways to speed up the process, including compiling it to mex. In the documentation, extended capabilities lists code generation using the matlab compiler.
I can't get this to work. I've tried calling using a second function without success.
I get the following error, which I do not know how to overcome...
"Failed to compute constant value for nontunable property 'WindowLength'. In code generation, nontunable properties can only be assigned constant values."Jack Lathamhttps://in.mathworks.com/matlabcentral/profile/authors/9175739-jack-lathamtag:in.mathworks.com,2005:Question/4743982019-08-01T08:04:30Z2019-08-22T14:53:46ZDraw a circle and measure the white pixels area insideHello everyone, a binary image is obtained. The work is to draw concentric cirles in the image and calculate the area of the white pixels in each circle. The objective is to get a curve.
I attached an image as an example.Hassan Khalilhttps://in.mathworks.com/matlabcentral/profile/authors/12263878-hassan-khaliltag:in.mathworks.com,2005:Question/4771722019-08-22T09:36:52Z2019-08-22T14:53:19ZReturning an additional value that is not part of the fitness function or objective for all population evaluation in GACan anyone please help by showing the code how can I return an additional value (Sigma) that is not part of my fitness function (Mean). I know how to return all the populations, scores but I'm not sure how to return this additional value (sigma). I see many have asked this question but no one showed in a code rather than just directing us to use the nested functions. Here is my code:
% the function to be optimized
[objective] = Optimization_Function(x,Pi,Pa,LogG,d,lifetime,Demand,BasePrice,HighPrice,...
LowPrice,dis_rate_lamda,Geo,Wells_cost,Wells_rate,DStage,Operating_Fields,row,Amt,FOPEX,VOPEX)
.
.
.
.
expectedNPV = mean(NPV_C);
sigma = std(NPV_C); %%%%% I need this value for every population evaluation
NewObjective = (expectedNPV)
objective = - NewObjective;
% my optimization code
clear gaoutfunction
options = optimoptions('ga','OutputFcn',@gaoutfunction,'UseParallel',true);
startTime = tic;
fun = @(x)Optimization_Function(x,Pi,Pa,LogNormal_G,d_cline,lifetime,Demand,BasePrice,...
HighPrice,LowPrice,dis_rate_lamda,Geo,Wells_cost,Wells_rate,DStage,Operating_Fields,row,Amt,FOPEX,VOPEX);
[xGA,fval] = ga(fun,nvars,[],[],[],[],lowbond,upbond,[],[],options);
time_ga_parallel = toc(startTime);
record = gaoutfunction();
gapopulationhistory = vertcat(record.Population);
gabesthistory = vertcat(record.Best);
gascorehistory = vertcat(record.Score);
Results = [gapopulationhistory gascorehistory];
% my output funciton which includes populations, scores but does not include sigma :(
function [state,options,optchanged] = gaoutfunction(options,state,flag)
persistent state_record
if isempty(state_record)
state_record = struct('Population', {}, 'Best', {}, 'Score', {});
end
if nargin == 0
state = state_record;
options = [];
optchanged = [];
else
state_record(end+1) = struct('Population', state.Population, 'Best', state.Best', 'Score', state.Score);
optchanged = false;
end
end
Can anyone please show me how to return sigma as I’m returning all the populations and their scores. Please note the score here is only the objective which is the mean. The sigma value is not part of the optimization but I need it to save the time rather than running the model again to evaluate it. Please help. Yaser Khojahhttps://in.mathworks.com/matlabcentral/profile/authors/8998848-yaser-khojahtag:in.mathworks.com,2005:Question/4767382019-08-19T17:59:01Z2019-08-22T14:50:07ZDeleting overlapping lines in a plotHi all,
I have a .fig file that is made up of red and black lines and I want to be able to export this as .pdf. Plot twist: Each of the red lines shown here has an underlying black line that I want to just get rid of, so it results in only purely-black and purely-red lines. Any idea how to solve this?
Thanks!
Hans Sunaryantohttps://in.mathworks.com/matlabcentral/profile/authors/9096811-hans-sunaryantotag:in.mathworks.com,2005:Question/4770752019-08-21T18:05:31Z2019-08-22T14:46:55ZMatlab - app designer - component name and callbackHi,
In App Designer
How can we know the name of a modified component when his callback is also connected to other component ?
Thkspatrick bouchehttps://in.mathworks.com/matlabcentral/profile/authors/15070757-patrick-bouchetag:in.mathworks.com,2005:Question/4739502019-07-29T16:01:18Z2019-08-22T14:45:59ZDraw partial spheroid include a spheroidI want to draw 1/8 spheroid include a small spheroid and output the geometry for mesh. But my current coding always have discontinue in the cutting plan.
Can anyone help provide a idea of cutting the spheroid in 1/8 not for showing but get the data.KOU DUhttps://in.mathworks.com/matlabcentral/profile/authors/13809686-kou-dutag:in.mathworks.com,2005:Question/4772082019-08-22T13:50:19Z2019-08-22T14:45:23ZParameter 1 is not a numberHi, ive got a problem with making my app to operate microscope. I try to change the mode in a SetFrameTransferMode function with a simple checkbox that returns the value (0 or 1), but i get an error saying "Parameter 1 is not a number". Here is part of the code, thanks for help in advance.
In properties i have:
FrameTransfer = 0
then there is a check box function:
function FrameTransferCheckBoxValueChanged(app, event)
value = app.FrameTransferCheckBox.Value;
app.FrameTransfer=value;
end
and the part where error apears
[ret]=SetFrameTransferMode(app.FrameTransfer);
CheckWarning(ret);
Here is explanation of how this funcion works, from the Software Dev Kit
unsigned int WINAPI SetFrameTransferMode(int mode)
%Description: This function will set whether an acquisition will readout in Frame Transfer Mode.
%Parameters: int mode: mode
% 0 OFF
% 1 ONKacper Gawinkowskihttps://in.mathworks.com/matlabcentral/profile/authors/15707063-kacper-gawinkowskitag:in.mathworks.com,2005:Question/4760092019-08-13T16:41:56Z2019-08-22T14:43:58ZHow to add regular sine wave in phased array toolbox?The built-in application allows you to simulate complex signals, but there is no way to build a normal sine. Could you help me in this matter?Stanislav Bezvitniyhttps://in.mathworks.com/matlabcentral/profile/authors/12422734-stanislav-bezvitniytag:in.mathworks.com,2005:Question/4771702019-08-22T09:33:48Z2019-08-22T14:43:08ZIssue with SimBiology - parameters from valid .sbproj not loadingHi, I am having an issue pertaining to some *.sbproj models. See for example the attached simple Lotka model version.
While the general model information indicates that there are 3 parameters, 4 reactions, 4 species etc.
SimBiology Model - lotka
Model Components:
Compartments: 1
Events: 0
Parameters: 3
Reactions: 3
Rules: 0
Species: 4
the following commands
m1.Reactions
m1.Parameters
m1.Species
result in display of reactions and species arrays only
SimBiology Reaction Array
Index: Reaction:
1 x + y1 -> 2 y1 + x
2 y1 + y2 -> 2 y2
3 y2 -> z
ans =
0×1 empty double column vector
SimBiology Species Array
Index: Compartment: Name: InitialAmount: InitialAmountUnits:
1 unnamed x 1
2 unnamed y1 900
3 unnamed y2 900
4 unnamed z 0
The parameter array is empty!
What is wrong with the attached 'lotka.sbproj' file? Strangly enough the simulation runs just fine producing the expected results. I attach the simulation script as well.
Any comments would be very appreciated. Memjeyhttps://in.mathworks.com/matlabcentral/profile/authors/8885777-emjeytag:in.mathworks.com,2005:Question/684782013-03-25T01:25:05Z2019-08-22T14:40:23Zwhy imwrite make image background become black ?Anyone can tell me why the imwrite make the image background become black, i inserted an image of something with background of white but after using code below i got perfect image but the background become black :
rgbImage = imread('wtmk.png');
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
reconImage=cat(3,redChannel,greenChannel,blueChannel);
imwrite(reconImage,'watermark.png','png');
Anything wrong with my code ?I Madehttps://in.mathworks.com/matlabcentral/profile/authors/4091038-i-madetag:in.mathworks.com,2005:Question/4770142019-08-21T11:29:11Z2019-08-22T14:38:04ZPlotting multiple piecewise functions onto the same graphHi!
I'm new to the program and i've been trying to plot two piecewise functions,
y(x) = piecewise(0<x<1.85, sin(523.26*pi*x), 1.85<x<3.7, 0, 3.7<x<5.55, sin(523.26*pi*x), 5.55<x<7.4, 0, 7.4<x<9.25, sin(523.26*pi*x));
and
y2(x) = piecewise(0<x<1.63, sin(463.08*pi*x), 1.63<x<3.26, 0, 3.26<x<4.89, sin(463.08*pi*x), 4.89<x<6.52, 0, 6.52<x<8.15, sin(463.08*pi*x));
onto the same graph, but i can't get the coding right. Would anyone be able to help?
Thank you so much in advanceMargherita Carlonhttps://in.mathworks.com/matlabcentral/profile/authors/15968082-margherita-carlontag:in.mathworks.com,2005:Question/2773362016-04-05T18:08:58Z2019-08-22T14:37:22ZHow to plot a weighted graph?for example: How to plot bellow graph?
G=[1 4 0.2
2 4 0.2
3 4 0.2
4 1 0.7
4 2 0.7
4 3 0.7
4 5 0.5
4 8 0.6
5 4 0.4
5 6 0.8
5 7 0.8
6 5 0.3
7 5 0.3
8 4 0.5
8 9 0.9
8 10 0.9
8 11 0.9
9 8 0.4
10 8 0.4
11 8 0.5
11 12 0.6
12 11 0.2];
and How to plot an unweighted graph?
Jack Iehttps://in.mathworks.com/matlabcentral/profile/authors/7861009-jack-ietag:in.mathworks.com,2005:Question/4772022019-08-22T13:23:18Z2019-08-22T14:36:33ZCompare two meshes for difference in valuesI feel like I should know how to do this, but apparently I don't have the patience to figure it out today.
I have two 'mesh grids' with assigned values in mx4 and nx4 arrays. I would like to compare the result values, column 4, for points which have the same coordinate values, columns 1:3. I can identify the coordinates of the points which are the same using intersect, but my attempts at getting the difference in result values through logic indexing have been unsuccessful.
data = struct('name',{'Original','Layered'});
[data(1).nums] = randi(100,100,4);
[data(2).nums] = randi(100,200,4);
rs = intersect(data(1).nums(:,1:3),data(2).nums(:,1:3),'rows');
compared = [rs,find(data(1).nums(data(1).nums(:,1:3)==rs,4))-find(data(2).nums(data(2).nums(:,1:3)==rs,4))];
Error: Matrix dimensions must agree.
I don't care that much about fixing this error specifically, if somebody knows a better way to do the comparison, this was just where my train of thought went.Bob Nbobhttps://in.mathworks.com/matlabcentral/profile/authors/7983890-bob-nbobtag:in.mathworks.com,2005:Question/4772132019-08-22T14:36:10Z2019-08-22T14:36:10Z"This canvas does not support painters" error flooding command windowI have an issue using the appeditor. The error "This canvas does not support painters" floods my command window. I am using an app that was created by another user on a different computer, possibly with a different version of MATLAB.Carson Layhttps://in.mathworks.com/matlabcentral/profile/authors/15795183-carson-laytag:in.mathworks.com,2005:Question/4771682019-08-22T09:28:06Z2019-08-22T14:35:32Zplotting Data vs timelineGreetings!
I would like to plot some Data against a timeline and I kind of managed to do so, but with the problem that I also plot the time itself in the Diagram.
Is there a possibility to hide the Timedata in the Diagram? Or do I need to change the Code?
I attached the Diagram just for clarification of the Problem.
Data = xlsread('Repräsentative Profile VDEW.xls','H0','B4:B99');
Time = xlsread('Repräsentative Profile VDEW.xls','H0','A4:A99');
order = 3;
framelen = 11;
sgf = sgolayfilt(Data,order,framelen);
xlabel('TIme');
ylabel('Power');
plot(Time,Data)
datetick('x', 'HH:MM')
hold on
plot(Time,sgf,'.-')
legend('signal','sgolay')
Thank you in Advance!Philip Bukovcanhttps://in.mathworks.com/matlabcentral/profile/authors/15966256-philip-bukovcantag:in.mathworks.com,2005:Question/4770512019-08-21T15:30:26Z2019-08-22T14:35:14ZVolume change in simbiologyI have a question about how Simbiology handles volume changes during a simulation. I understand that by assigning ConstantCapacity to false we can allow the capacity of a compartment to change according to some rule; as an example, a tumor compartment that responds to drug treatment. But how does Simbiology handle the concentration of species that reside in this compartment? If tumor is shrinking, the concentration of species within it will increase, which is an artefact.
Any comment would be greatly appreciate.Ardeshir Goliaeihttps://in.mathworks.com/matlabcentral/profile/authors/13077835-ardeshir-goliaeitag:in.mathworks.com,2005:Question/4770912019-08-21T20:12:47Z2019-08-22T14:29:35ZCan I write a script that keeps rows that are within 5% and 10 cells above and below a specific cell? The idea is to have a script that takes stable data eleminating the peaks and valleys.
I want to have that cell compared with the 10 before and after itself and if all this 21 values are within 5% then I can keep that data. That script should also be able to check all the rows of an excel spreadsheet.
Any suggestions and ideas are much appreciated! I am a newby trying to do advanced stuff :)Diego Dranutahttps://in.mathworks.com/matlabcentral/profile/authors/15981205-diego-dranutatag:in.mathworks.com,2005:Question/4770602019-08-21T16:23:46Z2019-08-22T14:26:25ZImplicit expansion with empty arraysI was just idly curious why scalar expansion of an empty array seems to work here (R2018a),
>> [1,2,3;4 5 6]-zeros(2,3,0)
ans =
2×3×0 empty double array
but not here,
>> [1,2,3;4 5 6]-zeros(2,0,0)
Error using -
Array dimensions must match for binary array op.Matt Jhttps://in.mathworks.com/matlabcentral/profile/authors/1440443-matt-jtag:in.mathworks.com,2005:Question/4772062019-08-22T13:39:45Z2019-08-22T14:24:40Zhow can I plot a unit step function?How can i plot a unit step function or a piecewise function in Matlab?
ie:
h(t)=u(t-2)-u(t-4)?
or another example:
h(t)={0 for t<0, 1 for 2<t<3, 0 for t>3
Also, how can i plot a periodic square wave with thresholds in matlab? Seba.Vhttps://in.mathworks.com/matlabcentral/profile/authors/15698963-seba-vtag:in.mathworks.com,2005:Question/4768772019-08-20T14:54:37Z2019-08-22T14:16:06Znormxcorr2 - technical reference documentHello,
Inside the normxcorr2 function in Matlab, it's written in the comments that:
"Our technical reference document on NORMXCORR2 shows how to get from equation 2 of the Lewis paper to the code below."
where can this technical reference document be found?
Thanks,
OlgaOlga Libermanhttps://in.mathworks.com/matlabcentral/profile/authors/9297505-olga-libermantag:in.mathworks.com,2005:Question/4764962019-08-17T07:11:16Z2019-08-22T14:12:38ZHow could I set the legend for a particular bar in a bar chart?I have a bar chart describing 22 groups of data (from the year 1997 to 2018), each group has 10 elements (see the below fig), now I want to set a legend for the 7th bar of year 2004 (a purple bar), how could I do that? Thanks a lot..Lin SUhttps://in.mathworks.com/matlabcentral/profile/authors/6889163-lin-sutag:in.mathworks.com,2005:Question/4765732019-08-18T10:49:06Z2019-08-22T14:10:46Zhow to enter function into app designer ? So I want to use UART prtocol into my project . I build the UART protocol ,but I want to use this protocol via appdesigner . So for exmaple I want to write the number In a Numeric Field box and to send this number to the UART protocol . how do I do it ?
this is my UART protocol :
%% Instrument Connection
% Find a serial port object.
obj1 = instrfind('Type', 'serial', 'Port', 'COM3', 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = serial('COM3');
else
fclose(obj1);
obj1 = obj1(1);
end
% Connect to instrument object, obj1.
fopen(obj1);
%%% Instrument Configuration and Control\
% Communicating with instrument object, obj1.
fwrite(obj1,23 , 'uint8');
in this last line of code :
fwrite(obj1,23 , 'uint8');
I send the number that I want to send in the UART protocol . But I want to enter this number (for example 23 in this case ) via NumericEditField in the app designer . How to do it ?
tomer polskyhttps://in.mathworks.com/matlabcentral/profile/authors/12906803-tomer-polskytag:in.mathworks.com,2005:Question/4772072019-08-22T13:45:42Z2019-08-22T14:09:21ZError Message " grpstats requires Statistics and Machine Learning Toolbox"I have just installed MATLAB but i keep getting an error message when running in-bult functions in Statistics and Machine learning tool box. The error message is " grpstats requires Statistics and Machine Learning toolbox." Matlab was able to find the function when i run "edit or which" but couldn't run it.
What could be wrong?
Stephen Famurewahttps://in.mathworks.com/matlabcentral/profile/authors/15956353-stephen-famurewatag:in.mathworks.com,2005:Question/4770922019-08-21T20:32:12Z2019-08-22T14:08:38ZPre-determine plot ranges?Given two vectors of the same length is there a way to determine the axes ranges that would result if the data were plotted without plotting the data?
I am looking to update xlim and ylim manually after the plotted data is changed* but with out relying on the automatic resizing as there are other things plotted that I dont want to be used in determining the plot ranges. Also I would rather not redraw the entire figure with just the modified data then redraw the larger thing.
(plotted data is changed*: I am manipulating the XData and YData parameter of plotted data directly with a handle.)
Chrishttps://in.mathworks.com/matlabcentral/profile/authors/3126987-christag:in.mathworks.com,2005:Question/887952013-10-01T13:10:21Z2019-08-22T14:08:15Zadd xy coordinates to a graph<</matlabcentral/answers/uploaded_files/312/untitled.jpg>>
hi, i have a graph like this picture, local maxmimus are shown with red points, but i also would like to show the related xy coordinates on graph by adding commands to existing code,not with data curser.
please help me if you canmaryamhttps://in.mathworks.com/matlabcentral/profile/authors/4521399-maryamtag:in.mathworks.com,2005:Question/4770502019-08-21T15:25:23Z2019-08-22T14:07:58ZIssues with readtable()Hello, I have been trying to import excel data files using GUI. I used
[a,b] = uigetfile;
t = readtable(fullfile(b,a));
t gets uploaded as a a table but the empty cells in the excel file appear as NaN in table t. How do I prevent this.
For some reason readcell, readvars dont work for me
I have also tried fillmissing but I get this
x = fillmissing(t,'constant',0)
Error using fillmissing/checkArrayType (line 552)
Invalid fill constant type.
Please help me!Salsabil Salahhttps://in.mathworks.com/matlabcentral/profile/authors/15996740-salsabil-salah