https://it.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-02-23T01:37:44Ztag:it.mathworks.com,2005:Question/5070232020-02-23T00:37:04Z2020-02-23T01:37:44ZHow to import data to produce velocity image dataAttached to this post is the data file, and I need help achieving these objectives:
Import SRAS_freq.txt and produce a velocity image of the data.
You will need to separate the x and y and frequency information from the loaded array.
The x and y axis spacing is different so the image is not square even though there are 200x200 data points, you should take this into account when creating the images.
The Acoustic wavelength used for the scan was 24 microns.
I am unaware on how to start this and possible technqiues to use. How would I approach this? all possible avenues are welcome.
Many Thanks to allJames Adamshttps://it.mathworks.com/matlabcentral/profile/authors/17578827-james-adamstag:it.mathworks.com,2005:Question/5070182020-02-22T23:16:58Z2020-02-23T01:33:18Zremoving all rows with duplicate information in two columnsHi there,
I have a large matrix with 5 columns. As an example ,imagine a=[1 2 3 4 5; 1 3 4 5 6; 1 2 3 5 5] is just a small sample of the larger matrix. I am trying to remove the rows where columns 1 and columns 5 match. So for my example matrix a, I would need to remove BOTH rows 1 and 3 since they have the same values in column 1 AND column 5. I know that the unique function can get me to the point where one of the rows is removed but I need both of them removed. I have been at this all day and am stumped (and it is probably a simple answer!)
Any help is much appreciated!
Erika Wellshttps://it.mathworks.com/matlabcentral/profile/authors/12470122-erika-wellstag:it.mathworks.com,2005:Question/5070172020-02-22T23:11:02Z2020-02-23T01:23:04ZHow to Plot A 3D Ring of any given shape?Say for example I have a 2D matrix that makes a simple shape like a star, rectangle or circle. How can I take this 2D shape and turn it into a 3D ring? If it was a star, a star shaped ring, if its a square, a square shaped ring and so on...Sushmitha Kudarihttps://it.mathworks.com/matlabcentral/profile/authors/10776880-sushmitha-kudaritag:it.mathworks.com,2005:Question/5070262020-02-23T00:57:30Z2020-02-23T01:19:45ZHow to organize and analyze my excel files in matlab?Hi I am new to matlab.
I use CellProfiler software to output large excel files(.csv).
Basically what I usually do is load a bunch of images from a bunch of wells across 5 or so treatment conditions. Each image has 20-30 bunch of biological cells labled with a fluorescent marker in ch00, ch01, ch02,ch03 etc..
I first segment the cells ( called objects) and make a shit ton of measurements on them ( e.g. size, mean intensity of a particular color channel, form factor etc...).
All I need to do is take mean and median values on all the measurements according to treatment and measurement type so I can stick them in graph pad prism to make figures.
I'd like a versatile script to account for changes in the types and numbers of measurements I am taking as well as the types and numbers of treatment conditions...
However, I am new to matlab so any help appreciated!
See attached for example file.Randy sthttps://it.mathworks.com/matlabcentral/profile/authors/9783302-randy-sttag:it.mathworks.com,2005:Question/5053902020-02-13T21:28:42Z2020-02-23T01:15:48ZHow can I add a button which pauses and resumes the code when pressed in the App Designer?I've got a simple code running a loop which displays the output in a value field in the app window. How do I do to add a button in the app which pauses code when pressed and when pressed again it makes it continue?
It basically has to do the same function as the Run/Pause/Continue button from matlab's toolbar.
Thanks in advanceCode23https://it.mathworks.com/matlabcentral/profile/authors/8917886-code23tag:it.mathworks.com,2005:Question/5056762020-02-15T17:40:16Z2020-02-23T01:12:52ZDesign IIR filter from absorption data Hello!
As the title says, and I have got the coefficients. This:
f = [125 250 500 1000 2000 4000];
alpha = [0.09 0.2 0.5 0.7 0.8 0.9];
N = 1; % Filter order
Fs = 44100 % Sampling frequency
w = f/fs*2*pi; % Frequency in radians
R = sqrt(1-alpha);
% Find R(z) coefficients:
[b,a] = invfreqz(R,w,N,N);
How do I go about from here, as I need to visualize the filter, e.g. a plot of the magnitude response?
Best regards,
MariusMarius Tøndel Eliassenhttps://it.mathworks.com/matlabcentral/profile/authors/14712141-marius-tondel-eliassentag:it.mathworks.com,2005:Question/2447542015-09-24T02:23:37Z2020-02-23T01:11:45ZHow should I write a script that generates a table containing the sin and cos values for X between 0° and 90°, in 1° increments?I am a fairly new user to matlab and need some help creating this table. There should be three columns labeled x, sin(x), and cos(x) and 91 rows for the values of x (0 through 90), sin(x), and cos(x). Thanks!Marc Mezzacappahttps://it.mathworks.com/matlabcentral/profile/authors/6992002-marc-mezzacappatag:it.mathworks.com,2005:Question/5070242020-02-23T00:55:01Z2020-02-23T01:05:26ZI can't activate my license. Matlab 2019b linux ubuntuYou might not have write permission on the License File or the folder. /home/antonio/.matlab/R2019b_licenses/license_antonio_40816183_R2019b.lic See your System Administrator for assistance. The specific error message texAntonio Avilix Hernandezhttps://it.mathworks.com/matlabcentral/profile/authors/17491067-antonio-avilix-hernandeztag:it.mathworks.com,2005:Question/5070022020-02-22T20:03:19Z2020-02-23T01:00:41Zstrjoin, string, remove a single space, while combining variables. I have to do this in this manner for a hw question, I know there are other ways to acomplish the same thing....
X = strjoin([ "The" , "cat" ], " ")
Y = strjoin([ "over" , "the" , "fence" ], " ")
Z = strjoin([ X ,"jumped", Y ,"." ], " ")
"Z" has a space between the end of string "Y" and the added period, I need to remove just that space while maintaining the rest of the spaces between the other strings.
How do I get.....
"The cat jumped over the fence." % no space between "fence" and "."
Tyler Younghttps://it.mathworks.com/matlabcentral/profile/authors/17206303-tyler-youngtag:it.mathworks.com,2005:Question/937392010-11-29T15:03:00Z2020-02-23T01:00:01ZHow do I launch MATLAB on Linux?I've completed the installation and activation of MATLAB on a Linux computer. How do I launch the application?
MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:it.mathworks.com,2005:Question/5070192020-02-22T23:29:27Z2020-02-23T00:22:08Ztime-dependant iteration through a loop?Hello
I am running a function with some subprocess that may take too long
I would like to advance to the next value of "n", if this subprocess takes too long.
for example below, after running TRYME_RUN(0.6,0.1) fro one hour, I would like to move to TRYME_RUN(0.6,0.2)
I tried various timer and 'while'/'if' tic toc but once it starts TRYME_RUN it does not go out...
Sorry in advance if I am note clear. Any help would be greatly appreciated ++
a
function MYFUNCTION
for alpha= [0.6]
for beta= [0.1 0.2 0.3]
TRYME_RUN(alpha,beta)
end
end
antoinehttps://it.mathworks.com/matlabcentral/profile/authors/6475725-antoinetag:it.mathworks.com,2005:Question/5070222020-02-23T00:21:15Z2020-02-23T00:21:15ZHow to write objective function for Bayesian Optimization (bayesopt)?Dear all,
I am using `bayesopt` method and I need to provide an objective function.
I have studied the https://uk.mathworks.com/help/stats/bayesian-optimization-objective-functions.html on how to write an objective function.
Where can I find more example of objective function in MATLAB?
Can anyone guide me how to write objective function for Bayesian Optimization?
Thank youErichttps://it.mathworks.com/matlabcentral/profile/authors/2884346-erictag:it.mathworks.com,2005:Question/5070132020-02-22T22:06:37Z2020-02-23T00:11:06Zhow to handle multiple way-points for 2D path followingI am trying to generate a path following profile from multiple way-points that I generated from path planning. My path following algorithm is in a MatLab function within a Simulink model which includes a controller and a simple kinematic model. I can run the Simulink model each time for one pair of successive way-points and get a sensible path between these successive way-points, but am struggling to feed in all 'pairs' of waypoints through the simulation and get an xy profile of the whole path. Am I approaching this problem from the correct angle ie asking the controller to calculate a path between each successive pair of way-points and plot the overall profile.William Campbellhttps://it.mathworks.com/matlabcentral/profile/authors/10967941-william-campbelltag:it.mathworks.com,2005:Question/5070092020-02-22T21:51:20Z2020-02-23T00:10:26ZEuler method and GraphHi, I have to solve a an ODE with the Euler method for two separate step sizes and have to place them on same graph. I'm very confused on how to do this... Please help me...
y'=1/y; Initial Condition y(0) = 1;
I have to use Euler method to solve for y(1) for step size deltat = 0.1 and also deltat = 0.01
This is as far as I got and I'm just completely stuck.....
t0=0; t1=1; dt=0.1; %define time range and step size
y0=1; %initial condition
t=t0:dt:t1;
y=zeros(size(t,1), size(t,2))
for i=1: ((t1-t0)/dt)
y(i+1)=y(i)+1/y(i)*dt
endNasir Hollidayhttps://it.mathworks.com/matlabcentral/profile/authors/16241844-nasir-hollidaytag:it.mathworks.com,2005:Question/5070212020-02-22T23:50:16Z2020-02-22T23:50:16ZSimEvents access class/object in MATLABI am trying to build a model of an OS scheduler in SimEvents. Using MATLAB code, I created a class to represent a Task that describes the behavior of the task (e.g. run for x steps, perform I/O for y steps, repeat m steps n times, and so on. I'm really stuck trying to figure out how to integrate this into the SimEvents environment.
For example, I see where I can use an entity generator, and use a MATLAB function block to return the delta-T for the next event generation. For example, the example of random generation works great.
function dt = getDT( )
dt = rand(1,1);
end
What I'd really like to do is to call my TaskList object that returns the time a new process is admitted to the system:
function dt = getDT()
dt = task_list.getNextStart();
end
But, I cannot seem to get the SimEvents system to be able to see the task_list object in the base workspace. I've tried using the ports and data manager and tag the variable as a parameter, but its not one of the known types and nothing I've tried seems to work.
Any advice? Thomas Briggshttps://it.mathworks.com/matlabcentral/profile/authors/17202339-thomas-briggstag:it.mathworks.com,2005:Question/5070042020-02-22T20:36:13Z2020-02-22T23:46:59ZSolving FitzHugh-Nagumo equations using ODE45Write a program to solve the FitzHugh-Nagumo equations for a single cell (i.e., without spatial coupling).
du/dt = c1u ( u − a)(1 − u) − c2uv +stim
dv/ dt = b (u − v)
where
a=0.13
b=0.013
c1=0.26
c2=0.1
stim is a stimulus current that can be applied for a short time at the beginning of the simulation.
u represents membrane potential and ranges from 0 (rest) to 1 (excited). v is a recovery variable in the same range. t is time in milliseconds.
How do you use MATLAB's ode45() function to integrate the system of differential equations? Input to the program should be the duration of the simulation; initial values for u, v, and t; the strength of the stimulus, and the time for which it is applied (typically a few ms). It;s output should include vectors for t, u and v.
Kate Heinzmanhttps://it.mathworks.com/matlabcentral/profile/authors/11998023-kate-heinzmantag:it.mathworks.com,2005:Question/49902011-04-07T11:37:16Z2020-02-22T23:33:20Zlength of audio samplehello!
I am trying to import an audio sample into matlab and get matlab to tell me the length of the sample. Please can someone help me with this ,
cheers.God'sSonhttps://it.mathworks.com/matlabcentral/profile/authors/2799599-god-ssontag:it.mathworks.com,2005:Question/5066142020-02-20T13:45:51Z2020-02-22T23:33:18ZHow to make this signal linear Here is my code so far on how to produce this plot. Any ideas on how to make this plot linear?
A = dlmread('signal_2.txt'); %Reads signal data file
x= A(:,1); %Time Variables
y= A(:,2); %Amplitude variables
Many ThanksJames Adamshttps://it.mathworks.com/matlabcentral/profile/authors/17578827-james-adamstag:it.mathworks.com,2005:Question/5007962020-01-17T19:00:15Z2020-02-22T23:32:55Zsolving equation with if statementsHello
I am trying to solve the following equation given input time and values (y) vectors.
I tried the following
syms theta kappa alpha
if time < alpha
eqn = exp(-kappa*time)==y;
else
eqn = exp(-kappa)*exp(-theta*(time-alpha))==y;
end
vars = [theta kappa alpha];
S=solve(eqn);
but it raises an error...
Conversion to logical from sym is not possible.
I tried to convert alpha into double (i.e. double(alpha) ) in the if statement but it did not work...
Any suggestions?
the data look like :
antoinehttps://it.mathworks.com/matlabcentral/profile/authors/6475725-antoinetag:it.mathworks.com,2005:Question/767902013-05-23T15:45:25Z2020-02-22T23:14:38ZEnable Title Printing & Page Boundaries in SimulinkAnyone know if there is a way to set "Show page boundaries" and "enable titled printing" as a default when creating new subsystem blocks? I keep having to enable these settings every time I copy a previous block, even if I had the settings changed in the block I copied from.
ThanksMichaelhttps://it.mathworks.com/matlabcentral/profile/authors/4064471-michaeltag:it.mathworks.com,2005:Question/5070162020-02-22T23:09:56Z2020-02-22T23:09:56ZNetwork Congestion and available bandwidth estimation? Could anybody please give me some idea about this please.
If we take maximum bandwidth of a link is X
And the current bandwidth is Y
Then the available bandwidth will be Z = X-Y
Is the available bandwidth estimation correct?
2.
We know,
If the network is congested then the bandwidth decreases significantly with the increase of RTT (Round Trip Time).
So, when the network will be congested that time available bandwidth will increase. Is this correct assumption?
Thank you in advance.Mohmmad Abu Yousufhttps://it.mathworks.com/matlabcentral/profile/authors/12955584-mohmmad-abu-yousuftag:it.mathworks.com,2005:Question/5064892020-02-19T20:34:18Z2020-02-22T23:07:04ZAssigning gpuArrays to different graphics cards In the example below I use a parfor loop to assign a different 256x256x256 (random k-space) matrix to each of my 2 GPUs. Theoretically, I can then process these matrices in parallel on the 2 GPUs (here I've done an ifftn). The problem is that the parfor loop is very slow (presumably overhead related). This operation takes 6.5 seconds on my machine. If I replace the 'parfor' with a simple 'for' (and run 1 GPU sequentially), this operation takes 0.2 seconds.
Is there an easy (fast) way to assign a gpuArray to a specific graphics card - such that future operations on this gpuArray will use the specified graphics card? Rather than using parfor, I would prefer to simply use asynchronous CUDA kernels (invoking one directly following the other in Matlab code) to run both GPUs in parallel.
Dims = [256,256,256,2];
Kspace = complex(rand(Dims,'single'),rand(Dims,'single'));
Image = gpuArray(complex(zeros(Dims,'single')));
tic
parfor n = 1:2
gKspace = gpuArray(Kspace(:,:,:,n));
Image(:,:,:,n) = ifftn(fftshift(gKspace));
end
tocRWShttps://it.mathworks.com/matlabcentral/profile/authors/213137-rwstag:it.mathworks.com,2005:Question/5070152020-02-22T22:45:53Z2020-02-22T23:04:56ZSums elements of a rowHello everyone!
I have the following problem (I bring an example):
I am in this initial situation:
Company worker1 worker2 worker3 worker4 worker5
AAAAA M F F F M
BBBBB F F M
CCCC M M F M
DDDDD F M
I would like to get the sum of M and F for each line and have this as the final result:
Company worker1 worker2 worker3 worker4 worker5 SumM SumF
AAAAA M F F F M 2 3
BBBBB F F M 1 2
CCCC M M F M 3 1
DDDDD F F 0 2
Finally, save it all in excel
I attach a piece of code that I wrote (I don't know if it is right or useful to achieve the required result)
clear all;
clc;
load('DBTot.mat');
%%
n=size(DBTot,1);
m=size(DBTot,2);
DBGender=DBTot(:,[1,(7:4:m)]); % selec only the gender
DBGender=table2cell(DBGender);
n1=size(DBGender,1);
m1=size(DBGender,1);
clear DBTot
strDBGender=string(DBGender);
Thank you all!
Riccardo Businhttps://it.mathworks.com/matlabcentral/profile/authors/13045775-riccardo-busintag:it.mathworks.com,2005:Question/5059542020-02-17T14:42:32Z2020-02-22T22:59:37ZError using ezplot commandHi.
I´m trying to make a graph using the command "ezplot". But I get this error message: "Index exceeds the number of array elements (1)" and "error in ezplot>ezimplicit". Would you please help me to figure out what´s wrong?
This is my code:
clear all
syms x x(t) T x_0 xT
T=2;
x_0=0;
F(t)=int(x(t)-(diff(x(t))^2),t,0,T)
D=functionalDerivative(F,x)
x_sol1= dsolve(D,x(0)==x_0, x(T)==xT)
x_sol1(t)=subs(x_sol1);
figure(1);
ezplot(x_sol1(t),0,T);Adriana Castillo Castillohttps://it.mathworks.com/matlabcentral/profile/authors/13495304-adriana-castillo-castillotag:it.mathworks.com,2005:Question/5069832020-02-22T17:24:47Z2020-02-22T22:52:08ZHow to color an image according to orientation of objects?I use the following code:
I = imread(picture);
BW = imbinarize(rgb2gray(I));
figure()
h = imshow(BW);
axis on
props = regionprops(BW, 'Orientation');
allAngles = [props.Orientation];
histogram(allAngles);
to get orientation histogram of all the objects on an image.
How can I get an image with orientations assigned for all the objects?
The following code seems not to work properly:
y= ismember(BW,find([props.Orientation]));
imagesc(BW+y )
title('Objects according to their orientations')
colormap()
As it shows only 2 colors, not the entire orientation spectrum.
I know it's probably like taking candy from a baby, but I'm a Matlab newbie.
youlhttps://it.mathworks.com/matlabcentral/profile/authors/17603637-youltag:it.mathworks.com,2005:Question/5068132020-02-21T13:46:10Z2020-02-22T22:47:36ZShell Application "Paste" CommandI would like to exexcute a paste command through the Shell applicaiton. I'm trying to replicate the VBA command
CreateObject("Shell.Application").Namespace(CVar(DestinationFolder)).self.InvokeVerb "Paste"
I've currently got the following:
objShell = actxserver('Shell.Application');
DestinationFolder = 'C:\';
objFolder = objShell.NameSpace(DestinationFolder);
objFolderItem = objFolder.Self;
But I'm getting the error
Undefined function or variable 'Self'.Afzalhttps://it.mathworks.com/matlabcentral/profile/authors/4169987-afzaltag:it.mathworks.com,2005:Question/5068872020-02-21T21:30:36Z2020-02-22T22:45:38ZGenetic algorithm plot diagram displayDear all,
I am having a few challenges with regards to GA displaying the plots from the plot function and saving the output results from the output function, while using the m file, however when put in optimization toolbox, the plot are displayed and the output functions are saved respectively. That draws me to the questions, what do I have to do to make the plots displays and save the out put functions using an m file as displayed below.
Thanks
Kind regards
Joshua Abam
function [x,fval,existflag,output,population,scores] = scr_gafunction(x)
options = optimoptions('ga'); %Define Optimization the solver
options = optimoptions('ga','PopulationSize',50,'Generations',50,'OutputFcn',@gascroutputdata); %Define the Population Size
%Define the generation Size %Define Ouput Function
options.SelectionFcn = ('selectionstochunif'); %Define the selection pattern
options.MutationFcn = ('mutationgaussian'); %Define the mutation methods
options.CrossoverFcn = ('crossoverheuristic'); %Define the crossover methods
options = optimoptions('ga', 'Display','diagnose','MaxStallGenerations',60); %Define Display function
%Define at what Generation is GA stall
%Define the Plot Function
scr_gafunction.options.PlotFcns = optimoptions('ga','PlotFcn',{@gaplotbestf,@gaplotrange,@gaplotscores,...
@gaplotselection,@gaplotdistance,@gaplotexpectation,@gaplotstopping})
options = optimoptions('ga','UseParallel', true, 'UseVectorized', false);
ObjectiveFunction = @weight; %fitness function
nvars = 3; % Number of variables
A = [0 0 -1]; %Linear Inequality Constraint matrix
b = [-0.0254]; %Linear inequality constraint vector (t_1+t_corr+t_fab)
Aeq = [1 -0.03 0]; %Linear equality Constraint matrix
beq = [77]; %Linear equality constraint vector
lb = [167, 3000, 0.0127]; %Vector of Lower bounds
ub = [173, 3200, 0.0286]; %Vector of Upper bounds
% Initial design point could be determined in 2 ways: One is to leave it to
% GA automatically generate; or it can be specified by the users.
%x0 = []; %Initial Feasible Point
nonlcon = @nonlinearconst; %Nonlinear constraints
Intcon = []; %Vector indicating variables that take integer values
%Excuate GA with output
[x,fval,exitflag,output,population,scores] = ga(ObjectiveFunction,nvars,A,b,Aeq,beq,lb,ub,nonlcon,Intcon,options)
Final_time = toc(startTime);
fprintf('GA optimization takes %g seconds.\n',Final_time)
endjoshua Abamhttps://it.mathworks.com/matlabcentral/profile/authors/5181076-joshua-abamtag:it.mathworks.com,2005:Question/5069462020-02-22T09:23:20Z2020-02-22T22:41:17Zconverting a matrix sequentially in to single columnI have a matrix of 600*12, then the idea is:
first to sequentially convert the first 1-30 row by 12 column in to single column.
and the second matrix from 31-60 row by 12 column in to single column and to continue from the column in step 1.
and this process extends to the end of 600 row
So how can i write a for loop to do this
kind regars
TESFALEM ALDADAhttps://it.mathworks.com/matlabcentral/profile/authors/17470342-tesfalem-aldadatag:it.mathworks.com,2005:Question/5068712020-02-21T18:27:02Z2020-02-22T22:40:26ZHow to make group of ones more systematic approach?I have this groups of ones:
group = [ ones(size(Ribboned_100.unpatterned_B1.(string(var(i))))); 2 * ones(size(Ribboned_100.unpatterned_B10.(string(var(i))))); ...
3 * ones(size(Ribboned_100.unpatterned_He.(string(var(i))))); 4 * ones(size(Ribboned_100.unpatterned_MD.(string(var(i)))));...
5 * ones(size(Ribboned_100.unpatterned_HT.(string(var(i))))); 6 * ones(size(Ribboned_100.unpatterned_BT.(string(var(i)))));
7 * ones(size(Ribboned_100.unpatterned_NI.(string(var(i)))))]
and I have this set of strings here:
XT= {'B1','B10','He','MD','HT','BT','NI'};
I think the way I make "group" above is not efficient and there should be a way to make the "group" systematically using "XT".
Any suggestion?Zeynab Mousavikhamenehttps://it.mathworks.com/matlabcentral/profile/authors/14179884-zeynab-mousavikhamenetag:it.mathworks.com,2005:Question/1532542014-09-03T09:51:04Z2020-02-22T22:34:43ZMATLAB scaling issue on high-resolution (high DPI) displaysHi there,
I have just installed MATLAB R2014a on my 13.3" laptop with a resolution of 3200*1800, running on Windows 8.1.
When I start MATLAB it opens in a scaled window, and menu bars and the editor windows are somewhat blurry. At some point (from one to 15 minutes) the window resizes and the scaling turns off. Editing windows and menu bars are now illegibly small due to the bad dpi support of MATLAB i presume.
I have the feeling that the display change it is related to right-clicks, but am not sure about that.
Has anyone ever experienced similar problems? Does MATLAB support high-resolution displays and I haven't found the checkbox to click? Is there any option (I guess in Windows) to force scaling?
I could work on a blurry scaled screen, but not when the system changes unexpectedly.
Cheers, and thanks in advance.Andreashttps://it.mathworks.com/matlabcentral/profile/authors/5587703-andreastag:it.mathworks.com,2005:Question/5070142020-02-22T22:33:46Z2020-02-22T22:33:46ZFunction input problem in produce TEC mapsHello to everyone
I produce TEC maps from Code's ionex files. I have a lot of files and the format of these files is "CODG0010.13I" like this. I produce TEC maps, but I want to do this as a function. I entered will be history, these files will be processed and I will be able to produce my TEC maps. But I don't know how I can write the date as input of files like this "CODG0010.13I". Thanks for the help.Özgehttps://it.mathworks.com/matlabcentral/profile/authors/11106827-ozgetag:it.mathworks.com,2005:Question/5069302020-02-22T05:57:18Z2020-02-22T22:32:26ZUndefined function 'min' for input arguments of type 'struct'.Undefined function 'min' for input arguments of type 'struct'.
Error in mapminmax.create (line 12)
xmin = nnet.array.safeGather(min(x,[],2));
Error in mapminmax (line 51)
[y,settings] = mapminmax.create(x,param);
Error in GLCM_MainTotalDemo (line 46)
P_train=mapminmax(P_train,0,1);
%********* program **************************
clear all;
clc;
%% BUILD DORSAL HAND VEIN TEMPLATE DATABASE
tic; %% calculating elapsed time for execution
%% load mat files
load('db5.mat');
load('db6.mat');
%% reshape into row vector
reduced_testdata = reshape(reduced_testdata,1,4,10); % one row,four column and 15(60/4) group for 20 classes
reduced_traindata = reshape(reduced_traindata,1,4,20); % one row,four column and 45(180/4) group for 20 classes
%% adjust dimension
% Adjust matrix dimension
P_test = cell2mat(reduced_testdata); % Convert cell array to matrix
P_train = cell2mat(reduced_traindata);
%% rearranges the dimensions of P_test and P_train
C = permute(P_test,[1 3 2]);
P_test = reshape(C,[],size(P_test,2),1);
C = permute(P_train,[1 3 2]);
P_train = reshape(C,[],size(P_train,2),1);
%% labeling class
train_label=load('train_label_2.txt');
test_label=load('test_label_2.txt');
% %%% Normalisation
%
% P_train=P_train/256;
% P_test=P_test/256;
%% Normalisation by min max
P_train=mapminmax(P_train,0,1);
P_test=mapminmax(P_test,0,1);
%% %%PCA low dimension reduction
P_train = P_train';
%%% if classes are 20 then eiganvectors not exceed then 179
model = perform_pca(P_train,rank(P_train)-1); %rank(P_train)-1
test_features= linear_subspace_projection(P_test, model, 1);
P_train=model.train';
P_test=test_features';
%% classfication
predictlabel = knnclassify(P_test, P_train, train_label,3,'euclidean','nearest');
cp = classperf(test_label,predictlabel);
Conf_Mat = confusionmat(test_label,predictlabel);
disp(Conf_Mat);
[c_matrix,Result,RefereceResult]= confusion.getMatrix(test_label,predictlabel);
%% % Evaluate Performance
[FPR, TPR,Thr, AUC, OPTROCPT] = perfcurve(predictlabel, test_label,1);
figure,
plot(TPR,FPR,'r-','LineWidth',1);
xlabel('False positive rate')
ylabel('True positive rate')
title('ROC Curve for Classification ')
Tbl = table(FPR, TPR, Thr)
%% FAR = FPR = FP/(FP + TN) and FRR = FNR = FN/(FN + TP)
fprintf('\n\n Overall accuracy:%f%%\n',cp.CorrectRate*100);
%% calculating elapsed time for execution
toc
Balaji M. Sontakkehttps://it.mathworks.com/matlabcentral/profile/authors/7099670-balaji-m-sontakketag:it.mathworks.com,2005:Question/5070072020-02-22T21:18:05Z2020-02-22T22:24:12ZHow can I separate the arrays when making a table?I need to make table from two arrays.
One array is matrix of n*1 and the other array is n*5. When I make table the table size is n*2 and I want to be n*6.
Any thouhgt?
I use this command:
table=table(ttestnames,ttest_result_p);Zeynab Mousavikhamenehttps://it.mathworks.com/matlabcentral/profile/authors/14179884-zeynab-mousavikhamenetag:it.mathworks.com,2005:Question/5069842020-02-22T17:34:23Z2020-02-22T22:22:58ZHow to make pairplots using gplotmatrix?Attached is the data of three categories. I need to make pairplots for them. They have different length. How can I swal with data that has different length?
According to the data, B10 with the value of "8331" what would be its pair in B1?
And my next question is that how I can define "group" for gplotmatrix in the data that I have? Should it be like
group={'B1','B10','HE'}
And do you have any other suggestion to make pairplots other than gplotmatrix?Zeynab Mousavikhamenehttps://it.mathworks.com/matlabcentral/profile/authors/14179884-zeynab-mousavikhamenetag:it.mathworks.com,2005:Question/5064962020-02-19T21:30:46Z2020-02-22T22:22:36ZHow to Turn Imagesc to x and y?I have the following file MunkS_500Hz.shd.mat,
munkProfile = load('MunkS_500Hz.shd.mat');
pressureWave = munkProfile.pressure;
pressureWave = abs(pressureWave);
squished = squeeze(pressureWave);
figure
plot(squished);
logged = log(squished)
imag = imagesc(logged);
that I can make into a 501 x 1001 matrix. Now I want to take this matrix from imagesc and put make it into a 3D point cloud. I would like some advice on how to do this. (I am unable to insert the file here even as a .zip file, I can email it to you if you think you can help).
Sushmitha Kudarihttps://it.mathworks.com/matlabcentral/profile/authors/10776880-sushmitha-kudaritag:it.mathworks.com,2005:Question/5066742020-02-20T18:38:22Z2020-02-22T22:16:03ZSum across columns with shiftI have a matrix a, let say 20 rows and 10 columns. I want to obtain an array b where b(1)=a(1,1)
b(2)=a(1,2)+a(2,1)
b(3)=a(1,3)+a(2,2)+a(3,1)
...
b(20+10-1)=a(20,10)
In practice, every row of the a matrix is shifted right by one column with respect to the row above and then the elements of each column of the resulting (larger) matrix are summed. Is it possible to obtain this without loops and without building the big shifted matrix?Andrea Consolehttps://it.mathworks.com/matlabcentral/profile/authors/17479596-andrea-consoletag:it.mathworks.com,2005:Question/5069752020-02-22T15:34:09Z2020-02-22T22:13:23Zalgorithm for computing 𝜋 is due to Archimedes: how steps can be repeated The following algorithm for computing 𝜋 is due to Archimedes:
1. Start with 𝑎 = 1 and 𝑛 = 6.
2. Replace 𝑛 by 2𝑛.
3. Replace 𝑎 by sqrt(2 − sqrt(4 − 𝑎))
4. Let 𝑙 = 𝑛𝑎/2.
5. Let 𝑢 = na/2
6. Let 𝑝 = (𝑢 + 𝑙)/2 (estimate of 𝜋)
7. Let 𝑒 = (𝑢 − 𝑙)/2 (estimate of error)
8. Repeat steps 2 – 7 until 𝑒 becomes smaller than a given tolerance 𝑡𝑜𝑙.
9. Output 𝑝 and 𝑒
Write a function that implements this algorithm. Use your function to determine 𝑝 and 𝑒 for 𝑡𝑜𝑙 = 10^(=k)
, 𝑘 = 2, 3, … , 10.
I have written a code but i do not know how to write it so that if the value of e is larger than tol then steps 2-7 repeated. I have written this :
```
function [p,e] = algorithmPi(tol)
a=1
n=6
n=2*n
a=sqrt((2-(sqrt(4-((a)^(1/2))))))
l=(n*a)/2
u=l/(sqrt((1-(a)^2)/2))
p=(u+l)/2 % estimate of pi
e=(u-l)/2 % estimate of error
if e<tol
disp('done')
else
n=2*n
a=sqrt((2-(sqrt(4-((a)^(1/2))))))
l=(n*a)/2
u=l/(sqrt((1-(a)^2)/2))
p=(u+l)/2 % estimate of pi
e=(u-l)/2 % estimate of error
end
end
Anastasia Kyriakouhttps://it.mathworks.com/matlabcentral/profile/authors/17300432-anastasia-kyriakoutag:it.mathworks.com,2005:Question/5069702020-02-22T14:54:54Z2020-02-22T22:08:10ZCreate a logistical variable based on time rangeI have some air quality data from an office ranging from the 9th October to the 21st October.
I am trying to understand how air quality behaves when nobody is in the office. Therefore I need to seperate out the data from when nobody is in the office.
This is between 6:30pm and 6:30 am every day, apart from the 12th, 13th, 19th and 20th, when the office is empty all day (weekends).
I am assuming I can use a timerange to create a logistical variable which I can then use to index.
How do I create this logistical variable to seperate out these desired time ranges?
I have included some sample data, this is a subset because the excel file is very large in its totality
Two important things to note is that there a far more column variables in reality than I have attached and that in MATLAB the datetime variable changes from a xx/xx/xxxx xx:xx:xx to xx-xx-xxxx xx:xx:xx formatWilliam Garretthttps://it.mathworks.com/matlabcentral/profile/authors/16620309-william-garretttag:it.mathworks.com,2005:Question/5070112020-02-22T22:00:38Z2020-02-22T22:07:36ZPCREAD: Not all points defined in the header could be loaded.I have the following function to export data into .ply format. However when I use
ptCloud = pcread('OutputFile.ply')
it looks like all the properties of ptCloud is empty.
Data File: Data File
Code to Export as .ply:
function write_ply(fname, P) %C
% Input: fname: output file name, e.g. 'data.ply'
% P: 3*m matrix with the rows indicating X, Y, Z
% C: 3*m matrix with the rows indicating R, G, B
num = size(P, 2);
header = 'ply\n';
header = [header, 'format ascii 1.0\n'];
header = [header, 'comment written by Sush\n'];
header = [header, 'element vertex ', num2str(num), '\n'];
header = [header, 'property float32 x\n'];
header = [header, 'property float32 y\n'];
header = [header, 'property float32 z\n'];
header = [header, 'property uchar red\n'];
header = [header, 'property uchar green\n'];
header = [header, 'property uchar blue\n'];
header = [header, 'end_header\n'];
data = [P'];
%, double(C')];
fid = fopen(fname, 'w');
fprintf(fid, header);
dlmwrite(fname, data, '-append', 'delimiter', '\t', 'precision', 3);
fclose(fid);Sushmitha Kudarihttps://it.mathworks.com/matlabcentral/profile/authors/10776880-sushmitha-kudaritag:it.mathworks.com,2005:Question/5070102020-02-22T21:54:16Z2020-02-22T22:03:49ZVisualizing 3 dimensional arrayI'm sorry if this is a stupid question, but I've really been scratching my head on this one. Maybe explaining exactly what I'm trying to do might help. Basically I'm simulating the temperature of a car battery over time during the course of a race. Then I change a parameter of how much the battery is cooled, and reiterate the loop. So my array is ~ 6000x15x20.
The value in each index represents temperature. The rows represent the "i'th" timestep (say every 0.1 seconds). The columns represent the "j'th" lap. The k index represents the heat transfer coefficient. So for example, T(end,:,1) would represent the temperature at the end of each lap with a heat transfer coefficient of 1(or some multiple of the index).
What i'm trying to do is visualize the temperature vs. time of the battery for a range of heat transfer coefficients. I can't figure out how to actually format this data as vectors to make a 3d plot, or surface plot, or whatever makes sense for the data. I think maybe I could reformat the 2d array of each k index into a vector, but then i'm not sure where to go from there.
I would really appreciate any advice you guys could provide. Thanks!Andrew DeCenzohttps://it.mathworks.com/matlabcentral/profile/authors/14521173-andrew-decenzotag:it.mathworks.com,2005:Question/5070122020-02-22T22:03:28Z2020-02-22T22:03:28ZF-OFDM filtering for 5GI saw in the LTE HDL toolbox, there's this example of HDL code generation for F-OFDM transmitter.
https://www.mathworks.com/help/ltehdl/examples/hdl-code-generation-for-filtered-ofdm-f-ofdm-transmitter.html
However I couldn't really find any mention of F-OFDM filtering in 3GPP release 15. Is this only a candidate filtering scheme that has not been standardized yet? If there are any pointers that link F-OFDM to the standard, can you please share them with me?
Thanks,
-SurangaSuranga Handagalahttps://it.mathworks.com/matlabcentral/profile/authors/8743231-suranga-handagalatag:it.mathworks.com,2005:Question/5070082020-02-22T21:42:20Z2020-02-22T21:46:14ZHow to delete a whole table in the matlab?I am running a loop which builds table and I need to delete the whole table for the next table. I used clear like "clear tablename" command but the table did not deleted.
Any suggestion?Zeynab Mousavikhamenehttps://it.mathworks.com/matlabcentral/profile/authors/14179884-zeynab-mousavikhamenetag:it.mathworks.com,2005:Question/5069962020-02-22T19:15:25Z2020-02-22T21:39:23ZHow can I connect nodes?Hello,
Please, How can I connect a geometric figure if i have the coordinates of nodes. I want to follow the trajectory which is in black but I obtain the trajectory which is in orange. I don't know why I have this errors?.
Here is the code:
clear;
clc;
close all;
X(:,1)=[0.0140,0.0105,0.0154,0.0056,0.0074,0.0180,0.0123,0.6412,0.6737,0.7130,0.2720,0.7874,0.8181,0.8661,0.7452,0.6080,0.0356,0.0389,0.0430,0.0460...
0.6494,0.2667,0.5811,0.6038,0.5528,0.5182,0.7235,0.6969,0.0048,0.0006, 0.0027,0.0010,0.2617,-0.0026,-0.0005,0.0046,0.1725,0.1558,0.1514,0.1323...
0.1486,0.1158,0.1150,0.2440,-0.0016,-0.0047,-0.0024,0.0017,0.1145,1.1199, 1.2009,1.1071,1,1.0575,0.2577,1.1857,0.0089,0.0083,0.0121,0.0062...
0.0097,0.0039,0.0027,0.0091,0.2854,0.2486,0.2614,0.2514,0.2217,0.2440, 0.2018,0.1959,0.1043,0.4611,0.4313,0.4093,0.2487,0.3634,0.3894,0.3383...
0.3226,0.0335,0.2109,0.9103,0.9548,0.9906,0.7441,0.2358,0.4866,0.0001, 0.0284,0.0221,0.0227,0.0238,0.1911, 0.3093, -0.0003, 0.3257, 0.2398, 0.0346]';
%
X(:,2) =[0.0324,0.0287,0.0270,0.0296,0.0252,0.0363,0.0381,-0.0627,-0.1206,-0.0668,-0.0371,-0.0761,-0.1605,-0.0894,-0.0052,-0.0097,-0.0291,-0.0367...
-0.0307,-0.0243,0.1489,-0.0496,0.1513,0.0809,0.2105,0.1515,0.1438,0.2167,0.0218,0.0217,0.0184,0.0152,-0.0614,0.0147,0.0124,0.0154,0.1058,0.1224...
0.0995,0.0930,0.0786,0.1054,0.0862,-0.0382,0.0098,0.0087,0.0072,0.0105,0.0701,0.0307,0.1104,-0.0420,0,-0.1237,-0.0372,-0.1393,-0.0163,-0.0205...
-0.0185,-0.0139,-0.0125,-0.0115,-0.0147,0.0210,0.1326,-0.0251,0.1629,0.1263,0.1193,0.0935,0.1389,0.1123,-0.0287,0.1496,0.1975,0.1461,-0.0628,0.1420...
0.0983,0.1778,0.1377,-0.0218,-0.0269,-0.0021,-0.1043,-0.2113,0.0594,-0.0647,0.0930,0.0061,0.0445,0.0486,0.0404,0.0331,0.0866,0.0980,0.0021,-0.0214...
-0.0515,0.0396]';
X=X(:,1:2);
xx=X(:,1);
yy=X(:,2)
plot(X(:,1),X(:,2),'o','LineWidth',1.5,'MarkerSize',9)
%
xlim([-0.2 1.4])
ylim([-0.25 0.25])
%Compute a boundary around the points using the default shrink factor.
k = boundary(xx,yy);
hold on;
plot(xx(k),yy(k));
Thanks
asmae mnebhi-loudyihttps://it.mathworks.com/matlabcentral/profile/authors/9519446-asmae-mnebhi-loudyitag:it.mathworks.com,2005:Question/5070002020-02-22T19:57:48Z2020-02-22T21:20:28ZPlotting piecewise, data from matrices/vectors This is how my plot looks.
Preferably it would look like this both in the start and in the end (for both red and blue).
I have tried to use:
P = [0 0 0 0 4 10.7 19.2 31.4 46.88 66.87 91.6 121.81 158 198.6 244 298.5 360 425 493 578 663 710 740 757 768 772 776 779 ...
780 780 780 780 780 780 780 780 780 780 780 780 780 780 780 780 780 780 780 780 780 780 780 0 0]'; % The data for the blue one
pw = piecewise(cond1,val1,cond2,val2,...)
% P as val1
I want it to go straight down to 0 after the last 780, not gradually as seen in the first picture.
But I can't get it to work. Any suggestions as to how I could acheive this?
Jørgen Myklebusthttps://it.mathworks.com/matlabcentral/profile/authors/16074934-jorgen-myklebusttag:it.mathworks.com,2005:Question/5069912020-02-22T18:29:11Z2020-02-22T21:10:58Zextracting the overlapping area from a shape file using a grid vector of latitude and longitude Hello Dears,
I have a grid cells of location ( latitude and longitude ) for a certain area. The task i wanted to do is to calculate all gris areas overlapping with in the watershed. Assume the grid is square so it would be so easy to calculate the area, but some the areas are irregualr due to the shape of the watershed.
So i have so many square and irrgular overlapping pixes to be calculated. I kindly appreciate some one with smart idea to figure this out.
BestTESFALEM ALDADAhttps://it.mathworks.com/matlabcentral/profile/authors/17470342-tesfalem-aldadatag:it.mathworks.com,2005:Question/5070062020-02-22T21:04:51Z2020-02-22T21:07:35ZHow to combine two cell arrays?I need to combine two cell arrays:
cellarray1= {'P'} {'A'} {'Pi'} {'Ab'} {'Pa'}
and
cellarray2={'e'}
I want to make this cell array:
newcellarray= {'e','P','A','Pi','Ab','Pa'}
I used:
{{'cell_combination'},cellarray1(1:end)}
but did not work. any suggestion?
Zeynab Mousavikhamenehttps://it.mathworks.com/matlabcentral/profile/authors/14179884-zeynab-mousavikhamenetag:it.mathworks.com,2005:Question/5070052020-02-22T20:37:18Z2020-02-22T21:06:50ZHow to programmatically stop simulation when output convergesI am running a model to do somthing like Monta Carlo simulation.
The output will get to a stable value after enough time, sometimes it takes longer, sometimes it takes less time.
To save the simulation time (there are several thousands of simulations to do), how can I programmatically set dynamic simulation time or stop simulation when output gets stable?
If there is even a solution for parallel computing, that would be even better.
Thanks and BRYunyu Huhttps://it.mathworks.com/matlabcentral/profile/authors/2039229-yunyu-hutag:it.mathworks.com,2005:Question/5069892020-02-22T18:05:37Z2020-02-22T21:05:54ZSimple Frequency Response FunctionI am trying to make a function that outputs the following frequency response of an FIR system:
where b is a vector of filter coefficients, w is a vector of angular frequencies, and output H is a complex-valued frequency response. I think I need a for loop to account for the summation, but I am not sure how to go about this (I am a MATLAB novice).
Thanks!Jonathan Medinahttps://it.mathworks.com/matlabcentral/profile/authors/16153393-jonathan-medinatag:it.mathworks.com,2005:Question/5069312020-02-22T05:58:29Z2020-02-22T21:02:54Zhow to use fir1 for highpass filter with window i have a problem while using fir1 with highpass and window function .
ex.
fc=input('cutoff frequency : ');
fs=input('sampling frequency : ');
order=input('order : ');
[b,a] = fir1(order,(2*fc)/fs,'high',rectwin(order+1));
but when i use '(order+2)' , there is no problem.
fc=input('cutoff frequency : ');
fs=input('sampling frequency : ');
order=input('order : ');
[b,a] = fir1(order,(2*fc)/fs,'high',rectwin(order+2));
the key point :: i want to use order = 5 and i want the result of 5 filter coefficients .anchitta sangsawanghttps://it.mathworks.com/matlabcentral/profile/authors/17413217-anchitta-sangsawangtag:it.mathworks.com,2005:Question/5069472020-02-22T09:30:42Z2020-02-22T21:00:25ZExtract numbers from lines in a txt file. Onset times from experimental data.Hi,
This problem should be familiar to people working with behavioral data, but I was unable to find a previous answer that would work for me.
I am trying to extract the onset times of certain conditions during an experiment.
The data is organised as in the enclosed file. I want to extract the lines starting with:
'WaitForScanner.OnsetTime'
'Tune.OnsetTime'
and
'ImagineMelody.OnsetTime'
and then extract the numbers at the end of these lines (5-digit onset times in ms) as variables,
work with them a bit in matlab: subtract scanneronset from tuneonset and imagineonset, and convert them to seconds,
and output them in two separate txt files (tuneonset.txt and imagine.txt).
When that works for one subject, I plan to loop over many subjects and also different sessions per subject (different txt file, same principle).
Best,
Andreas
Andreas Voldstadhttps://it.mathworks.com/matlabcentral/profile/authors/17599695-andreas-voldstad