https://es.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-02-24T00:18:00Ztag:es.mathworks.com,2005:Question/5018792020-01-24T20:37:37Z2020-02-24T00:18:00Zi got this error "upper range value must be greater than lower range value" in ANFIS app.Training loaded sucessfully but when i click on generate FIS by sub.clustering method, then the following error occured. what should i do now.
Muhammad Faisal Shehzadhttps://es.mathworks.com/matlabcentral/profile/authors/7186453-muhammad-faisal-shehzadtag:es.mathworks.com,2005:Question/5069302020-02-22T05:57:18Z2020-02-24T00:17:16ZUndefined 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://es.mathworks.com/matlabcentral/profile/authors/7099670-balaji-m-sontakketag:es.mathworks.com,2005:Question/5071512020-02-23T23:25:22Z2020-02-24T00:07:50ZEditor Tabs Moved to Bottom of WindowThe tabs in my MATLAB editor somehow moved to the bottom of the editor window. How can I put them back at the top? I tried to set the layout to the default, but this didn't move them.Douglas Sondakhttps://es.mathworks.com/matlabcentral/profile/authors/8068466-douglas-sondaktag:es.mathworks.com,2005:Question/5071562020-02-24T00:05:51Z2020-02-24T00:05:51ZCompress image with PCM encoderFor an equation like x(t)=A*sin(2*pi*f*t) the result is a code like this:
%Analog signal
f=2; %maximum freq of the input signal
fs=5*f;
t=0:1/fs:1;
a=2;
x=a*sin(2*pi*f*t);
%Amplitude shifting
x_pos=x+a;
%Quantization
quant=round(x_pos);
%decimal to binary
encoder=de2bi(quant, 'left-msb');
%receiver
decoder=bi2de(encoder,'left-msb');
%shifting the amplitude back
x_out=decoder-a;
My question is, for a given a .PGM image, how can I compress it with a PCM encoder following this steps(analog signal- sampler-quantizer-encoder-decoder) and change its bits per pixel?Marian-Catalin Pirvulescuhttps://es.mathworks.com/matlabcentral/profile/authors/12104169-marian-catalin-pirvulescutag:es.mathworks.com,2005:Question/5067472020-02-21T06:13:22Z2020-02-24T00:05:06ZImproving performance of a complex for loopI have a Matrix of size (300000X4). This is getting generated from a simulator that is running 200 particles for 1500 timesteps, hence producing 300000 rows of data. So, each of these 200 rows represents one timestep worth of data for one particle. The 4 columns are position and velocity components (Px, Py, Vx, Vy).
Now I am trying to create a new matrix that will be of dimension (3000000,10) where the columns will be the velocity values of the 5 nearest neighbors of a particle (at a particular timestep). The number of columns is 10 because I am going for 5 enighbours (i.e., Vx and Vy components of 5 nearest neighbors).
Currently, I can do it with for loops (pseudocode below), but I was wondering if it can be vectorized to speed up the computation. Any help or pointers (vectorizing or improving the approach) are much appreciated.
ROWS = 300000; %no of data rows
PARTICLES = 200; %no of particles
myData = rand(ROWS, PARTICLES); %matrix that holds my initial data from simulator, using dummy here
neighbors = 5;
neighborVelocity = zeros(ROWS,neighbors*2); %Allocating space for the final matrix to be generated
for t = 1:1500 %for each timestep
start = (t-1)*PARTICLES+1;
finish = (start-1)+PARTICLES;
currData = myData(start:finish,:); %Data for current timestep
temp = zeros(PARTICLES,neighbors*2); %For saving the processed data for current timestep
for m = 1:200 %for each particle
particle = currData(m,1:2);
allParticlePos = currData(:,1:2);
particleVelocity = currData(m,3:4);
allParticleVel = currData(:,3:4);
[Idx,~] = knnsearch(allParticlePos,particle,'K',neighbors);
nearest = allParticleVel(Idx,:); %The Velocities of the nearest neighbors are stored
%Some reshaping to save the nearest velocities in a intended format
nearest = reshape(nearest.',1,[]);
temp(m,:) = nearest;
end
neighborVelocity(start:finish,:) = temp; %Storing the particula timestep data
endRafihttps://es.mathworks.com/matlabcentral/profile/authors/10220564-rafitag:es.mathworks.com,2005:Question/5071472020-02-23T23:00:00Z2020-02-24T00:04:41ZAppdesigner: Loading a MAT file - Difference between doing it from MATLAB vs from within Appdesigner. If I load a MAT file from the MATLAB prompt e.g. load('Default_Patient.mat') it will nicely add:-
'Default_Patient 'ZaphodBeeblebrox'
...to the MATLAB Base workspace.
But, if I use the same command from within Appdesigner (even in the Startup Fn) I get:
'Default_Patient 1 x 1 struct'
where 1 x 1 struct contains: 'Default_Patient 'ZaphodBeeblebrox'
1) I don't understand why there is a difference - when it is exactly the same command.
2) Is there a way of just adding the 'ZaphodBeeblebrox' part to the Base workspace (when doing this from Appdesigner) and loading from a MAT file ?
Thank you in anticipation of a kind and helpful answer.Marco Frieslaarhttps://es.mathworks.com/matlabcentral/profile/authors/5140415-marco-frieslaartag:es.mathworks.com,2005:Question/5071552020-02-24T00:03:13Z2020-02-24T00:04:09ZPlease Help with Matlab questionCreate a random 7 x 7 matrix called M. (Hint: use the randi function)
Create a random 7 x 7 matrix called M. (Hint: use the randi function
Use logical indexing to replace any of the values less than 3 with 9.
Use for loops and vector concatenation to create a vector that contains all the values in the forward diagonal direction (red), and another vector that contains all the values in the backward diagonals (blue)Jennifer Wenghttps://es.mathworks.com/matlabcentral/profile/authors/17265114-jennifer-wengtag:es.mathworks.com,2005:Question/5071532020-02-23T23:46:08Z2020-02-24T00:02:38ZNumbering table and selecting valueHi,
This is a section of my program where I display the top 5 values for steel sections (from a manually inputted list of values), and then gives an options to select one of the sections to move on to further calculations.
How can I create the table to list the options 1-5, and then use the disp function to input a 1-5 number which will select the corresponding value?
Also, I have tried using the disp function and just typing in the full section but for some reason it gives a different Resistance value to the corresponding section in the list. Any thoughts?
Thanks,
Finlay
crossSectionInfo = sortrows( crossSectionInfo, 'Resistance' );
bestCrossSectionIndex = find( crossSectionInfo.Resistance > Mr, 5, 'first'); % five sections with suitable Mp resistance
disp( crossSectionInfo(bestCrossSectionIndex,:) )
result = input('Which steel section would you like to select?:','s');
disp( 'Value is');
disp(crossSectionInfo.Resistance(Name==result));
Finlay Briertonhttps://es.mathworks.com/matlabcentral/profile/authors/14185974-finlay-briertontag:es.mathworks.com,2005:Question/5060832020-02-18T04:20:52Z2020-02-23T23:59:02Zhistogram2 versus mvnpdfI have two variables and would like to create a joint PDF. I am mainly interested in the shape of the PDF and not the actual probability. My variables are two column arrays: u and v. I first tried using histrogram2(u, v), but was unsure if that was the correct function to use. I then tried using the mvnpdf function to check. I tried JPDF = mvnpdf( [u ,v] ). I then plotted the result with scatter3(u,v,JPDF). I got a different shaped distribution curve than the histrogram2 curve. Can anyone explain why they would produce different shaped curves?
Sylviahttps://es.mathworks.com/matlabcentral/profile/authors/12425762-sylviatag:es.mathworks.com,2005:Question/5071542020-02-23T23:55:21Z2020-02-23T23:55:21ZLoad data into experience buffer: DDPG agentI am using RL toolbox version 1.1 with Matlab R2019b and using the DDPG agent to design a controller. Is there a way to load in data (state, action, reward, next state) collected from real experiments into the experience buffer before startting training?Daksh Shuklahttps://es.mathworks.com/matlabcentral/profile/authors/8957585-daksh-shuklatag:es.mathworks.com,2005:Question/5071412020-02-23T21:36:31Z2020-02-23T23:54:58ZWrite multiple vectors into .dat fileI have been working with some data from a recent experiment and would like to move the data into a .dat file. However I have multiple vectors and require them in the same file.
Say I have the vectors:
x = [1, 2, ...];
y = [3, 4, ...];
How would I go about doing this?
Robert Placehttps://es.mathworks.com/matlabcentral/profile/authors/14673950-robert-placetag:es.mathworks.com,2005:Question/5067062020-02-20T23:37:34Z2020-02-23T23:54:45ZFinding adjacent pixels of a certain color around a blue pixel in an imageI am trying to write a function named countBlueWithAdjacentColor which receives the name of an image as input and returns the number of blue pixels that have an adjacent pixel (any direction) that is of the color specified by an 1-by-3 array named color which contains the red, green, and blue values that define the color in RGB (0-255) form.
Required function name and parameters: countBlueWithAdjacentColor(iName, color).
Sample function call: countBlueWithAdjacentColor('Image03.tif', [0,255,0])
Returned by function: [8]
.MICHAEL DZENZEOLhttps://es.mathworks.com/matlabcentral/profile/authors/17374662-michael-dzenzeoltag:es.mathworks.com,2005:Question/5064872020-02-19T20:28:15Z2020-02-23T23:53:49ZCubic smooth spline plot in 3d for several layersHello I have vectors
iv3,iv28,iv48,iv68,iv133,iv268,iv398 (each of length 83x1 - positive real numbers)
and one vector named strikes (length 83x1 - positive real numbers)
The iv3 vector refers to implied volatility data from day 3, the iv28 from day 28 and so on (this means we have a time axis of 7 days with day 3,day 28,...,day 398)
I need to do smooth spline interpolation for each pair (strikes,iv3) ,(strikes,iv28), ...,(strikes,iv398) and I use csaps().
csaps() works totally fine in 2d. Problem is I need to put all 2d plots in one 3d plot. But I do not need one surface over the whole observations in 3d, rather for each day and each pair (strikes,iv28), (strikes,iv48), ....(strikes,iv398) one smoothing spline (in total 7 splines per pair and time) -
spline1 one on (strikes,iv3, day3) ,
spline2 one on (strikes,iv28, day28)
,...,
spline7 one on (strikes,iv398, day398)
I came so far to plot the (unsmoothed) 3d observation graph (without the splines).
Now i need to do the smoothing for each observation pair in 3d.
Since csaps() and fnplt() do not work for 3d I need a workaround for 3d.
Also important is that I would like to have a smoothing parameter (lambda) which determines the smoothnes of the spline. As mentioned csaps does this perfectly, but does unfortunately not work for 3d graphics!
--------------------
To the graphic below! Every dot line needs to get its spline that smooths the data. Splines are missing in the graphic!
Plot command was (here for day 3) plot3(repmat(3,length(strikes),1),strikes,iv3,'.')
This was commanded then for each data tripel (days,strikes, iv), hence the other lines.
And here the day3 data with yellow=spline(via csaps(strikes,iv3,0.001)) and blue=real observations
Kind Regards
GabrielGabriel Fouillonhttps://es.mathworks.com/matlabcentral/profile/authors/17561336-gabriel-fouillontag:es.mathworks.com,2005:Question/3494422017-07-19T14:55:44Z2020-02-23T23:53:02ZHow to solve the 'StopFcn' error when the cause is "Vectors must be the same length."I have got a simulation file for a grid-tie inverter, which I am going to leave its image below. When I run the simulation, I receive the following error:
Error evaluating 'StopFcn' callback of block_diagram 'DC2ACGRID2'.
Caused by:
Vectors must be the same length.
I cannot figure out what vectors are causing this trouble. Any help is very much appreciated.
<</matlabcentral/answers/uploaded_files/83337/error-pic.png>>
sara yazdanihttps://es.mathworks.com/matlabcentral/profile/authors/8614879-sara-yazdanitag:es.mathworks.com,2005:Question/5071042020-02-23T17:42:18Z2020-02-23T23:47:33Zhow can i call a function that i want to use it after?I need to write a fuction that the input in nothing and the output is a format with fields that match the format .pdb
I worte this:
function kovetz= clom()
[choseK,choseD]=uigetfile('*.ent','shemkovetz');
kovetz=pdbread([choseK,choseD,]);
end
I have an error like this:
Error using uigetfile
Too many input arguments.
Error in clom (line 2)
[choseK,choseD]=uigetfile('*.ent','shemkovetz');eli manasherovhttps://es.mathworks.com/matlabcentral/profile/authors/17613696-eli-manasherovtag:es.mathworks.com,2005:Question/5060652020-02-17T23:40:53Z2020-02-23T23:47:22ZSelecting values to make further calculationsHi,
I am trying to complete the next step of my coding to design steel portal frames. For my next calculations I need to select a rafter section so I can do my stanchion calculations based on the resistance of my chosen rafter section. How can I select one of my displayed sections below and use the moment resistance as stated to continue my calcs.
Thanks
Lr = L/2 + h/tand(theta); % N is the distance from stanchion to base of reactant line where it meets the ground level
syms m
eqn = m^2/(2*w) + m*(5*Lr/3 - L/3) + w*L^2/8; % derived graphical method equation
M = solve(eqn,m);
m1 = max(double(M));
Y = -(w/2)*(-m1/w).^2 + w*L^2/8;
R = -(m1.^2/w) - m1.*Lr;
Mr = Y - R; % Target rafter Mp
disp (table( Mr ))
% Values from Blue Book put into directory to suggest members
Name = ["254x102x28"; "254x146x31"; "254x146x37"; "254x146x43"; "305x102x25"; "305x102x28";
Resistance = [97.1; 108; 133; 156; 94.1; 111; 132; 148; 169; 196; 171; 198; 233; 149; 181;
crossSectionInfo = table( Name, Resistance );
crossSectionInfo = sortrows( crossSectionInfo, 'Resistance' );
bestCrossSectionIndex = find( crossSectionInfo.Resistance > Mr, 5, 'first'); % five sections with suitable Mp resistance
disp( crossSectionInfo(bestCrossSectionIndex,:) )
result = input('Which steel section would you like to select?:');
disp( 'Value is');
disp(crossSectionInfo.Resistance);
Finlay Briertonhttps://es.mathworks.com/matlabcentral/profile/authors/14185974-finlay-briertontag:es.mathworks.com,2005:Question/5067042020-02-20T22:53:34Z2020-02-23T23:38:32ZHow to prevent MATLAB from replacing a predefined integral with besselj?I am asked via a partial differential equations class to verify that . This needs to be done by comparing the graph of besselj(0,x) over a pre-defined interval of x to the integral as stated, and see how close the graph of the integral is to MATLAB's default besselj(0,x) function.
However, MATLAB replaces the numeric computation of the integral with besselj(0,x) during the running of the code (I put the integrand in a separate function file and named it besselintegrand, then used the integral command in the file I will submit for the class), making the graphical comparison useless as it is computing besselj(0,x) twice and plotting both, resulting in the exact same graph for both the integral and besselj(0,x), instead of computing besselj(0,x) and then computing the integral and then graphing both functions as different entities. It is as if it is ignoring the integral, as something in MATLAB seems to go "Oh, this integral looks like besselj(0,x), let's just compute that instead of actually computing the integral."
Why do I want MATLAB to not default the integral to besselj(0,x)? Because I am asked to comment on the accuracy of the integral in comparison to MATLAB's default function. I can't get that if MATLAB replaces the integral with the default function that I am trying to compare the integral to!
Is there a way to prevent MATLAB from defaulting the computation of the integral to besselj, so that the actual output of the integral can be compared to besselj graphically? Or do I have to get sneaky and use some trigonometric identities to "trick" MATLAB into not recognizing the integral as besselj(0,x)? If there is a way to prevent MATLAB from doing this in the first place?
A classmate has tried using the symbolic math toolbox, and the system literally rewrites his integral in the output to besselj(0,x) so even the symbolic math toolbox has this behavior.Galen Baumgartnerhttps://es.mathworks.com/matlabcentral/profile/authors/17300869-galen-baumgartnertag:es.mathworks.com,2005:Question/5069472020-02-22T09:30:42Z2020-02-23T23:34:23ZExtract 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://es.mathworks.com/matlabcentral/profile/authors/17599695-andreas-voldstadtag:es.mathworks.com,2005:Question/5056762020-02-15T17:40:16Z2020-02-23T23:32:59ZDesign 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://es.mathworks.com/matlabcentral/profile/authors/14712141-marius-tondel-eliassentag:es.mathworks.com,2005:Question/5071452020-02-23T22:29:48Z2020-02-23T23:32:26ZNeed help on Minesweeper with formatting issues.I am in need of help understanding this problem. Not sure where to go from my code i Have. so far i have created a 10x10 random array and labeled another array with every number in the rand(10) thats greater than .85 = 1. Also i have made the 2x2 corners top and bottom safe spots 'equaling 0'.
clc, clear, format compact
% Place mines
mine_probabilities = rand(10);
mine = mine_probabilities > 0.85;
% Make the beginning/end "safe"
mine(1:2,1:2) = 0;
mine(9:10,9:10) = 0;
disp(mine)
The next step is:
INITIALIZE GAME WINDOW: Create a new 10x10 array called game_window. This is the “ﬁeld” that will be displayed while you are playing your game.
Every element in game_window should be -1, EXCEPT for where your “player” is located:
• Create a new variable my_position = [1, 1]; to describe your player’s current position (in terms of row, column).
• Set the corresponding element (element (1,1)) of game_window equal to 100. This is how you know where your player currently is.
Nathen Eberhardthttps://es.mathworks.com/matlabcentral/profile/authors/17128919-nathen-eberhardttag:es.mathworks.com,2005:Question/5071482020-02-23T23:04:47Z2020-02-23T23:18:36ZHow to replace the 5 in my vector with decreasing numbers like 5,4,3,2,1x(3:4,3:5) = 5Pallav Patelhttps://es.mathworks.com/matlabcentral/profile/authors/17249684-pallav-pateltag:es.mathworks.com,2005:Question/5071492020-02-23T23:08:19Z2020-02-23T23:14:45Zplotting with respect to time%% Givens
m=2; %kg
k=200; %N/m
x0=0.05; %meters
x_dot=2; %m/s
%% Solution Part A
Wn= (k/m)^0.5;
c= (2*m*Wn);
Cc= (2*m*Wn);
Zeta= c/Cc
%% Solution Part B
for t=0:10
C1=x0;
C2=x_dot+Wn*x0;
x = @(t) (C1+C2*t)*exp(-Wn*t)
end
I want my function to plot with respect to time. The ezplot generated begins the x-axis at -5.5, however since this is a plot of response with respect to time, -5.5 does not exist. Long story short, how can I make my plot go from a certain time range of 0s to 10s. Thank youAreg Arzoomanianhttps://es.mathworks.com/matlabcentral/profile/authors/13536756-areg-arzoomaniantag:es.mathworks.com,2005:Question/5069162020-02-22T03:39:27Z2020-02-23T23:09:25ZCELL2MAT does not support cell arrays containing cell arrays or objects.
hello guys.Can you understand Chinese?The sentence in blue means that "CELL2MAT does not support cell arrays containing cell arrays or objects".I never see any error like this.I translated it into English by Google Translator.So it may be not accurate.Do anyone experience this error.Could you please tell me how to do?By the way,my MATLAB version is R2019b,the code is earlier.So i think whether the old version and the new version are incompatible.I think the code itself don't have grammatical errors.Thank you for your answer!Berney Lihttps://es.mathworks.com/matlabcentral/profile/authors/11118088-berney-litag:es.mathworks.com,2005:Question/349462012-04-09T18:14:01Z2020-02-23T23:09:11Zcar license plate character recognition using neural networksir again i have one big query...iwant to recognize the license plate charactyer using neural network...but really i m too much confuse that how could i find the link between segmented characters and neural network....means i m unable to find syntax of giving segmented characters as i/p of neural...plese ans me..if any idea...please.........any one help me.....snehahttps://es.mathworks.com/matlabcentral/profile/authors/3427039-snehatag:es.mathworks.com,2005:Question/5071262020-02-23T19:56:15Z2020-02-23T22:56:48Zkeep getting errors on matlabt = xlsread('trandom','E2:E59');
y = xlsread(rtemp.xlsx','H2:H59');
N=58;
for i=1:N
A=[N sum(sin(t(i)) sum(cos(t(i))
sum(sin(t(i)) sum(sin(t(i))*sin(t(i)) sum(sin(t(i))cos(t(i))
sum(cos(t(i)) sum(sin(t(i))cos(t(i)) sum(cos(t(i))*cos(t(i))];
B=[sum y(i)
sum(y(i)sin(t(i))
sum(y(i)cos(t(i))];
end
X=A\B
idea is to solve ax=b for x, where ive written sum= summation of each i term of t or y
keep getting errors, not confident with matlab
Thanks for any help givenBoss Manhttps://es.mathworks.com/matlabcentral/profile/authors/11512976-boss-mantag:es.mathworks.com,2005:Question/5070092020-02-22T21:51:20Z2020-02-23T22:54:29ZEuler 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://es.mathworks.com/matlabcentral/profile/authors/16241844-nasir-hollidaytag:es.mathworks.com,2005:Question/5071382020-02-23T21:17:43Z2020-02-23T22:54:24ZHow do I set up code for an RK4 Method?I want to set up code for an RK4 method using y'=sin(t)*(1-y). I started in Excel but ran into some issues. I want to use MatLab but I have'nt ever messed with it besdes basics. Any pointers?
Christina Myershttps://es.mathworks.com/matlabcentral/profile/authors/17281257-christina-myerstag:es.mathworks.com,2005:Question/5071462020-02-23T22:48:39Z2020-02-23T22:48:39Zhelp for creating a 2D lookup table . I want to create a table F so that I could searh values ffrom the table by F(x,y). When I am using the scatteredInterpolant , some points i get inf values. Why it happens ??? for the neighboring values around x y , I got the right values. Thank you so much ！！！！！！！！！！！！！！！！！！！vvf vvffhttps://es.mathworks.com/matlabcentral/profile/authors/13051884-vvf-vvfftag:es.mathworks.com,2005:Question/5068352020-02-21T15:37:40Z2020-02-23T22:45:43ZPointer to Simulink FunctionSuppose I have a custom C function that accepts a function pointer as an argument,
float cFunc(float val, float (*ptrFunc)(float)) {
return ptrFunc(val);
}
and within Simulink, I defined a Simulink Function called "slxFunc" that takes a float as an input and outputs a float.
How do I obtain the pointer to slxFunc so that I could feed it to cFunc using a C-caller block?
Much appreciated, thanks.Carlos Mahttps://es.mathworks.com/matlabcentral/profile/authors/14335481-carlos-matag:es.mathworks.com,2005:Question/5071422020-02-23T21:53:21Z2020-02-23T22:45:20ZPrint figure without its titleHaving the simple code example below:
close all;
clear all;
clc;
x = rand(10,1);
y = rand(10,1);
f1 = figure(1);
plot(x,y,'*')
title('Random title')
print(f1,'-dpng', 'testpng', '-r600');
The "print" function will save the generated figure in my directory including the figure title. Is there any way I can save the figure without the title while keeping the "title" finction in my code for display purposes?
EDIT:
Consider there is no option to re-arrange the code lines. Please see updated code example below
close all;
clear all;
clc;
x = rand(10,1);
y = rand(10,1);
n = 0;
f(n+1) = figure(n+1);
plot(x,y,'*b')
title('Random title 1')
n = get(gcf,'Number');
f(n+1) = figure(n+1);
plot(x,y,'*r')
title('Random title 2')
n = get(gcf,'Number');
f(n+1) = figure(n+1);
plot(x,y,'*g')
title('Random title 3')
n = get(gcf,'Number');
figpr = input(['Please insert which figure to print (<',num2str(n),'): ']);
print(f(figpr),'-dpng', 'testpng', '-r600');MichailMhttps://es.mathworks.com/matlabcentral/profile/authors/9848527-michailmtag:es.mathworks.com,2005:Question/5070232020-02-23T00:37:04Z2020-02-23T22:39:14ZHow 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://es.mathworks.com/matlabcentral/profile/authors/17578827-james-adamstag:es.mathworks.com,2005:Question/5071442020-02-23T22:08:42Z2020-02-23T22:35:22Zreturns NaN and Inf instead of numberHello!
I'm trying to graph a function
P(n)=1-N!/(N^n(N-n)!)
for N=42^6
n=[10^6, 5*10^6, 10^7, 5*10^7, 10^8, 5*10^8, 10^9];
but when i calculated this function, i also received Inf and NuN.
I tried to use Symbolic Math Toolbox and HighPrecisionFloat Toolbox, but it is not helpfull in this situation.
How I can calculation and graph this function in Matlab?
Masha Kozakhttps://es.mathworks.com/matlabcentral/profile/authors/8854897-masha-kozaktag:es.mathworks.com,2005:Question/776532013-06-01T01:08:45Z2020-02-23T22:19:11Z3D image with Confocal Z-stacksHello,
I have a series of Z-stack confocal images, and I am trying to make a 3D image with matlab. I loaded these images into different plane of a m-n-plane matrix, but I do not know how to plot it into a 3D image.
Does anybody give me some suggestion on it? Thanks a lot in advance.
Best,
ZhongkuiZhongkuihttps://es.mathworks.com/matlabcentral/profile/authors/1223353-zhongkuitag:es.mathworks.com,2005:Question/5067932020-02-21T11:41:16Z2020-02-23T22:16:38ZHow could I code for loop with this values?Hi guys! I need a simple help from you.
I want to create a for loop with nested if-else condition. Afterthat I want to plot them. Could you guys help me please! I have written the pseudocode below. I need the coding based on this. Please help me out.
Thank you in advance.
%'A' consists some values (e.g. 40, 60, 30, 80, 70, 50, 90, 30);
for A % it will take first 2 values
% 'B' is the maximum value consisting of 2 values from 'A'
% e.g. max (40,60) = 60 then this 60 will be first value of A and last
% value will be 30 so max(60,30) is 60. Afterthat first value is 60 and 2nd value is 80
% so, max(60,80) is 80 likewise.
B = max (A);
% then 'C' is the last value from 'A' which is taken to get the 'B', will be assigned to 'C'.
C = 60; % for 2nd itaration C = 30, for 3rd C = 80, for 4th C = 70, for 5th C = 50 and so on..
% If C reduces 30% of B then,
x = C/10
fprintf ('This is your value %d',x );
else
fprintf ('This is not your value %d',x );
end
end
plot ('x' vs simulation time)
Mohmmad Abu Yousufhttps://es.mathworks.com/matlabcentral/profile/authors/12955584-mohmmad-abu-yousuftag:es.mathworks.com,2005:Question/5071402020-02-23T21:27:50Z2020-02-23T22:16:35Zhow can i create a 400 by 400 matrix with a pattern?The matrix is 400 by 400 and i need a -1 2 -1 pattern starting with 2. Like this:
absadgshttps://es.mathworks.com/matlabcentral/profile/authors/17572896-absadgstag:es.mathworks.com,2005:Question/5070622020-02-23T09:52:33Z2020-02-23T22:15:22ZIs it possible to calculate the average Manhattan distance between a set of 2D points with one function?Is there an easier way to calculate the average Manhattan distance between a set of points easier than I have it in my code? I have a matrix, which contains a set of 2D points (the columns corespond to the x and y coordinates).
%for the first point
[idx,~]=dsearchn(isec(2:end,:),isec(1,:));
sum=pdist2(isec(1,:), isec(idx+1,:), 'cityblock');
%for the rest of the points
for i=2:size(isec,1)-1
others=[isec(1:i-1,:); isec(i+1:end,:)];
[idx,~]=dsearchn(others,isec(i,:));
man=pdist2(isec((i,:), others(idx,:), 'cityblock');
sum=sum+man;
end
%for the last point
[idx,~]=dsearchn(isec(1:end-1,:),isec(end,:));
sum=sum+pdist2(isec(end,:), isec(idx,:), 'cityblock');
avg_dist=sum/size(isec,1);
As dsearch cannot calculate other distances than euclidean, I use it to find the index of the nearest point. After that I have to call the pdist2 function to measure the cityblock distance. What complicates things even more is the fact, that I have to exclude the current point (to which I'm trying to find the closest one); that's the purpos of my 'others' variable and the 2 pieces of code above and below the for-cycle.
To give a bit of context:
The goal is image segmentation. The points are actually line intersections in a grid. I want to calculate the average Manhattan distance in order to use the result as a treshhold to determine which points are roughly in the given row/column (unlike in the case of crosswords, sudokus, nonograms I'm not interested in the square areas between the lines, rather in the intersections).Bálint Udvardyhttps://es.mathworks.com/matlabcentral/profile/authors/9792299-balint-udvardytag:es.mathworks.com,2005:Question/5068282020-02-21T15:00:55Z2020-02-23T22:07:26ZDisplay only one eigenvalue of symbolic matrixHey :)
How to ask matlab to display only one (the first, biggest in magnitude) eigenvalue of a symbolic matrix (well the matrix only contains one strictly positive variable)?
The thing is that I need to insert the scalar(!) eigenvalue further into a function.
I tried eigs(A,1) but I get the error: "Error using eigs>checkInputs (line 214) First argument must be a double matrix or a function."
So i assumed it is because of the one variable in the matix...
Any help would be appreciated :)
Edit: Maybe here my code:
clear
a = 1.0; b = 0.0; m = 25.0; V = 13.0; Ecut = 50.0; w = 1.5*sqrt(m/(a+9/4*b)); Nx = 100; Ny = 100; Nz = 100; k = 1;
T = 1;
syms kx ky kz real
syms D positive
E = eye(4);
U = [0 0 0 1; 0 0 -1 0; 0 1 0 0; -1 0 0 0];
Jx = 1/2*[0 sqrt(3) 0 0; sqrt(3) 0 2 0; 0 2 0 sqrt(3); 0 0 sqrt(3) 0];
Jy = 1i/2*[0 -sqrt(3) 0 0; sqrt(3) 0 -2 0; 0 2 0 -sqrt(3); 0 0 sqrt(3) 0];
Jz = 1/2*[3 0 0 0; 0 1 0 0; 0 0 -1 0; 0 0 0 -3];
P = (D*(Jy*Jz+Jz*Jy)+1i*D*(Jx*Jz+Jz*Jx))*U/sqrt(3);
h = (a*(kx*kx+ky*ky+kz*kz)-m)*E+b*(kx*Jx+ky*Jy+kz*Jz)^2;
H = [h P; ctranspose(P) -transpose(h)];
dsum = 0;
counter = 0;
for i = 1:Nx
for j = 1:Ny
for l = 1:Nz
kx = w*i/Nx;
ky = w*j/Ny;
kz = w*l/Nz;
if abs(a*(kx*kx+ky*ky+kz*kz)^2-m)<Ecut
dsum = dsum + 8.0*D*D/V-8.0*k*T*ln(2.0*cosh(max(eig(H))/(2.0*k*T)));
counter = counter + 1;
end
end
end
end
F = @(D)dsum;
D = [0,10];
x = fminsearch(F,D)Rebecca Müllerhttps://es.mathworks.com/matlabcentral/profile/authors/12613899-rebecca-mullertag:es.mathworks.com,2005:Question/4897002019-11-06T05:00:00Z2020-02-23T22:05:58ZIs MATLAB compatible with macOS Catalina?Does MATLAB support macOS Catalina (10.15)?
MathWorks Support Teamhttps://es.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:es.mathworks.com,2005:Question/5069832020-02-22T17:24:47Z2020-02-23T22:02:36ZHow 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://es.mathworks.com/matlabcentral/profile/authors/17603637-youltag:es.mathworks.com,2005:Question/5071432020-02-23T22:01:53Z2020-02-23T22:01:53ZI need help with my While Loop!I have an original array (3D) called 'pixelArray' that I eventually need to crop 3 different ways. So I have 3 different sets of x1,x2,y1,y2 numbers that crop the original array in different ways.
I currently have it set up like this:
x1 = [52, 52, 52];
x2 = [480, 480, 480];
y1 = [4, 1, 205] ;
y2 = [392, 205, 392];
n = 1;
while n < 3
%crop rows
pixelArray(1:y1(n),:,:)=[];
pixelArray(y2(n):end,:,:) = [];
%crop columns
pixelArray(:,1:x1(n),:)=[];
pixelArray(:,x2(n):end,:)=[];
n =n+1;
end
But I want to save each iteration's new pixelArray as its own matrix. What is the best way to go about doing this?Uma Dixithttps://es.mathworks.com/matlabcentral/profile/authors/17317770-uma-dixittag:es.mathworks.com,2005:Question/2982152016-08-03T05:05:53Z2020-02-23T21:56:37ZHow to get ascii value of characters stored in an array? I have a problem, where i need to get the ASCII values of characters that are stored in a character array. Please help me with sufficient details. Thanks in advance.Adhihttps://es.mathworks.com/matlabcentral/profile/authors/7822304-adhitag:es.mathworks.com,2005:Question/968002009-09-30T19:50:00Z2020-02-23T21:46:39ZHow do I find my User Name in order to activate my license?When I try to activate my license, it asks for my User Name. How do I find this?
MathWorks Support Teamhttps://es.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:es.mathworks.com,2005:Question/62902011-04-27T07:15:19Z2020-02-23T21:27:15ZCreate an array of file names produced by system('dir /S *.ext')Hi there,
I know that you can search directories and sub-directories to provide a list of file names that meet a particular criteria using the code below:
[status,list]=system('dir /S *.mp3');
My question is: is it possible to create an array from the file names generated this way in order to create a loop for further processing??
Thanks in advance...bugguts99https://es.mathworks.com/matlabcentral/profile/authors/2628193-bugguts99tag:es.mathworks.com,2005:Question/5071352020-02-23T20:50:59Z2020-02-23T21:26:22ZError calling a function or indexing a variable, apparently the first line for plotting is wrong, can't figure out whats wrong with it...% Plotting the error curve
error = ( (40*c) / (m*g) )-( 1-exp( (-10*c)/m ) );
g = 9.81; % gravitational force
m = 68.1; % mass of parachutist
h1 = figure(1);
% Create vectors
c=(0:0.5:25)
y=zeros([1 50])
% Plot the various curves
plot(c, error(c, m, g)), 'r--', 'Linewidth', 3);
hold on;
plot(c,y,'k-', 'Linewidth', 3);
plot(5, error(5, m, g)),'.b', 'markersize', 10);
plot(c,y,'k-', 'Linewidth', 3);
xlabel('Drag coefficient c', 'fontsize', 20);
ylabel('Error', 'fontsize', 20);
title('Error as a function of c', 'fontsize', 20);
grid on;Michelle Gaughanhttps://es.mathworks.com/matlabcentral/profile/authors/17370215-michelle-gaughantag:es.mathworks.com,2005:Question/5071372020-02-23T21:03:08Z2020-02-23T21:22:39ZOptimization problem using gamultiobjThe goal is to find the pareto front of a problem using the following equations and constraints:
Equation 1:
Equation 2: (calulates the magnitude of C, D, and E once they are scaled by vector X)
F = sqrt( abs(C(:,1)*X(1) - C(:,2)*X(1)*X(2) + C(:,3)*X(3) + C(:,4)*X(3)*X(4)) ^ 2 +...
abs (D(:,1)*X(1) - D(:,2)*X(1)*X(2) + D(:,3)*X(3) + D(:,4)*X(3)*X(4)) ^ 2 +...
abs (E(:,1)*X(1) - E(:,2)*X(1)*X(2) + E(:,3)*X(3) + E(:,4)*X(3)*X(4)) ^ 2 )
where A3, A13, A23, Q, A34 are constant scalars, j is a complex number, and vectors C, D, and E are complex column vectors (e.g. C(:,1) has the size 100 * 1)
The constraints:
X(1) <= A constant value (JJ)
X(2) <= 1
X(3) <= A constant value (JJ)
X(4) <= 1
S >= some value
max(F) <= another value
Is this possible to be implemented using gamultiobj function?
reebal nimrihttps://es.mathworks.com/matlabcentral/profile/authors/13389673-reebal-nimritag:es.mathworks.com,2005:Question/5071392020-02-23T21:19:03Z2020-02-23T21:19:03ZBack substitution help examining code?I am examining this code for performing back substitution on naive gaussian elimination, and I can't seem to figure out where the x(j) is defined at? Or what exactly it's suppose to be prior to finding the solution x. I know that x is our solutions / solution vector to the system of equations when performing naive gaussian elimination. But I am not sure what exactly the value of a(i,j) * x(j) is at this step; is our solution vector x just suppose to be all zeros?? I am just not following how the solution vector is used in this step. Thanks for the help.
for i = n : -1 : 1
for j = i+1 : n
b(i) = b(i) - a(i,j)*x(j);
end
x(i) = b(i)/a(i,i);
endErik Hostonhttps://es.mathworks.com/matlabcentral/profile/authors/17336710-erik-hostontag:es.mathworks.com,2005:Question/5071202020-02-23T19:19:56Z2020-02-23T21:08:57Zanalytic solution with infinite sumHi,
I am having trouble figuring out how to write the code for this function that contains an infinite series.
Ti = 150;
T1 = 300;
T2 = 200;
L = 1;
alpha = 0.1;
delta_x = 0.05;
delta_t = 0.01;
N_time = 51;
N_space = 21;
x = linspace(0,L,N_space);
t = linspace(0,0.5,N_time);
I need to make the code so that it can compute this:
% I also need a little help in making the function. I have used syms m x t, but it doesn't work all the time.
c_m = (2/m*pi) ((Ti - T1)-(-1)^m*(Ti - T2))
T(x,t) = T1 + (T2 - T1)*(x/L) + %my unknown part: the infinite sum starting from 1 of c_n*exp(-m^2*pi^2*alpha*t/L^2)*sin(m*pi*x/L)Chien-Cheng Chiuhttps://es.mathworks.com/matlabcentral/profile/authors/8168931-chien-cheng-chiutag:es.mathworks.com,2005:Question/5063622020-02-19T10:49:11Z2020-02-23T21:03:09ZI have a function which is ranged from 0 microseconds to 50 microseconds. I just want to plot its exact copies from 0to50 microsecond,50 to 100microseconds,100 to 150 and so onClc;
Clear all;
Ts=1/200e6;
t=Ts:Ts:0.00005;
Y=[ones(1,2000) zeros(1,8000)];
x=sin(1256e6*t + 2198e10*t.^2);
z=x.*y;
plot(t,z)Devesh Yadavhttps://es.mathworks.com/matlabcentral/profile/authors/17579493-devesh-yadavtag:es.mathworks.com,2005:Question/5071362020-02-23T20:58:26Z2020-02-23T20:58:26ZHelp With Deep Learning Speech Command RecognitionHello!
I am new to deep learning, and am working on a speech recognition program for my engineering project. I have read through and run the Deep Learning Speech Recognition Example, but I need to train a neural network on several of my own speech commands to connect to an iRobot Create 2. I have two questions about this: firstly, how do I go about training the neural network on my own speech commands? I have many audio files of each command ready for training, but since the commands are different from those in the Deep Learning Speech Recognition Example, and the Example uses commands like splitData which refer only to the example command audio files, I am not sure the best way to go about doing this. Seccondly, once I have the neural net to where it can accurately recognize the speech commands, I want MATLAB to execute a task upon detecting a particular command. For example, one of my commands is "plot data." I will define a set of x and y values beforehand, and I want MATLAB to create a plot of this data when it detects a speaker saying the command "plot data." What is the best way to do this? I apologize as I am still very new to all of these concepts! They are fascinating, but I definitely still have a lot left to learn!
Thank you!Erika Mosshttps://es.mathworks.com/matlabcentral/profile/authors/13918005-erika-mosstag:es.mathworks.com,2005:Question/5070672020-02-23T11:08:05Z2020-02-23T20:53:23ZProblem related to fminbndI am finding the minimum value of Lr in the non-linear function. but whatever value of constants I change there is no effect on the minimum value. Also the minimum value I am getting is not correct.
fun=@(Lr)(((Vin*Cr*Lm)/(((((Z*Cc)+((A+(B*Cr))*((B*Cr)+C)*Lr))/Cc)+((ilm*ilm*Lm*Cc)/(((Z*Cc)+((A+(B*Cr))*((B*Cr)+C)*Lr))/Cc)))*(((1-D)*Ts)-((ilm*Lm)/(((Z*Cc)+((A+(B*Cr))*((B*Cr)+C)*Lr))/Cc)))))+((Lr*(((((Z*Cc)+((A+(B*Cr))*((B*Cr)+C)*Lr))/Cc)+((ilm*ilm*Lm*Cc)/(((Z*Cc)+((A+(B*Cr))*((B*Cr)+C)*Lr))/Cc)))*(((1-D)*Ts)-((ilm*Lm)/(((Z*Cc)+((A+(B*Cr))*((B*Cr)+C)*Lr))/Cc)))))/(Lm*Vin))+((C*Lr)/Vin));
[Lr,fval] = fmincon(fun,0,10e-6)
where all other variables are constants and their resp. values are givenPrajakta Ghatagehttps://es.mathworks.com/matlabcentral/profile/authors/15257711-prajakta-ghatage