https://in.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-04-21T22:49:20Ztag:in.mathworks.com,2005:Question/4577132019-04-21T22:49:20Z2019-04-21T22:49:20ZHow can i make the Temp matrix to contain all the values of T calculated in both conditions I want to make a Temp matrix which contains the T values calculated for tow conditions (H<=11) and (H>11). This code which i have written doesnt give me a matrix but gives a value. Also MATLAB says 'Size vector must be a row vector with real elements'. How do i solve thisYashita Singhhttps://in.mathworks.com/matlabcentral/profile/authors/14112491-yashita-singhtag:in.mathworks.com,2005:Question/4575412019-04-20T14:56:34Z2019-04-21T22:47:03Zregexrep for the neophyteHow to write expression to find and convert financial strings written with comma separator to be able to parse numerically?
Example stirng is something like:
recipients={'John Doe $200, Freddy Flint $132.40 SP19; Mary Lamb $1,423.00-SP19, Joe Blow $1,200'};
which is a list of student scholarship awards entered, unfortunately, free-style in a remarks field in an Excel spreadsheet. I need to parse by student and extract each.
I managed to find/return the location/token of the amounts containing the punctuation, but I'm illiterate with regexp and haven't figured out how to locate the comma then within that substring to remove it.
K>> regexp(recipients,'([$]\d+[,]\d+)','match')
ans =
1×1 cell array
{1×2 cell}
K>> ans{:}
ans =
1×2 cell array
{'$1,423'} {'$1,200'}
K>>
As can be seen, the original text also has "issues" in that the separator between students isn't consistent--it may be a comma or semicolon, not sure what else I'll find as I progress.
For context, this is the next step past the previous Q? of piecing back together disparate databases/spreadsheets...now that I can compare the award to the billing by account, I can find coding or other errors--but need to be able compare the details.
dpbhttps://in.mathworks.com/matlabcentral/profile/authors/28872-dpbtag:in.mathworks.com,2005:Question/4577122019-04-21T22:40:09Z2019-04-21T22:40:09Zode45 2dof mass spring damper system giving "index exceeds matrix dimension" error on line 488 of ode45.Im trying to place a specific value of force for each time step.
Please help im getting a weird error.
function [y, t] = solveMDOF2(M,C,K,force,tspan,ICs)
%State space coefficients (Xdot = AX + BU)
n=length(M);%degrees of freedom
A=[zeros(n),eye(n);-K/M,-C/M];
B=[zeros(n);inv(M)];
%e.g force is a 1*4001 matrix of force values
[t, y] = ode45(@(v,x) A*x + B*[0;force(v==tspan)], tspan, ICs);
end
Main
%% 2DOF mass-spring damper system undamaged
%System definition%
%mass 1
k1 = 7000;
c1 = 120;
m1 = 200;
%mass 2
k2 = 7000;
c2 = 120;
m2 = 200;
%Coefficients of Equation of Motion (MXdotdot + CXdot + KX = F)
M= [m1,0;0,m2];
C= [c1+c2,-c2;-c2,c2];
K= [k1+k2,-k2;-k2,k2];
tspan = 0:0.01:40; %Time span (seconds)
%generate random force inputs
forceinputs = rand(size(tspan));
ICs = [0;0;0;0]; %Needs 4 initial conditions (2DOF); assuming all zero initial conditions
%%Solve MDOF k = 7000
tic
[y_undmg,t_undmg] = solveMDOF2(M,C,K,forceinputs,tspan,ICs);
toc
Error
Unable to perform assignment because the size of the left side is 4-by-2 and the size of the right side is 4-by-3.
Error in ode45 (line 488)
yout(:,idx) = yout_new;
Error in solveMDOF2 (line 11)
[t, y] = ode45(@(v,x) A*x + B*[0;force(v==tspan)], tspan, ICs);
Error in test21042019 (line 28)
[y_undmg,t_undmg] = solveMDOF2(M,C,K,forceinputs,tspan,ICs);
>>
Jervell Thomashttps://in.mathworks.com/matlabcentral/profile/authors/9624412-jervell-thomastag:in.mathworks.com,2005:Question/4575972019-04-20T23:10:47Z2019-04-21T22:38:42ZHow to use polyfit to get the difference out of two functions?Hi
I have two datasets (X,Y). For every value of Y that corresponds to a value of X.
I am thinking of applying a polyfit command to get the best curve fitting for the data, and as a result I will come up with a function (slope+intercept).
How do I find the difference between those two functions? What command do I apply to subtract Function A from Function B?
Stelios Fanourakishttps://in.mathworks.com/matlabcentral/profile/authors/10865530-stelios-fanourakistag:in.mathworks.com,2005:Question/4577042019-04-21T21:06:36Z2019-04-21T22:28:33ZCan any one help me on thiss = load('pvev.mat');
pvev = s.pvev;
T = pvev{:,1};
PV = pvev{:,2};
ST = pvev{:,3};
EV = pvev{:,4};
for T = pvev{:,1}
if((PV > ST) & (PV > EV))
m = PV;
plot(T,m,'r','linewidth',2);
hold on
elseif((ST > PV) & (ST > EV))
m = ST;
plot(T,m,'g','linewidth',2);
elseif((EV > ST) & (EV > PV))
m = EV;
plot(T,m,'b','linewidth',2);
hold off;
grid on;
end
end
it says 'Operands to the || and && operators must be convertible to logical scalar values.
behailu woldesemayethttps://in.mathworks.com/matlabcentral/profile/authors/11433088-behailu-woldesemayettag:in.mathworks.com,2005:Question/4577092019-04-21T22:10:53Z2019-04-21T22:27:22ZI'm a beginner at Matlab, I need some help.ismail wajdihttps://in.mathworks.com/matlabcentral/profile/authors/15342560-ismail-wajditag:in.mathworks.com,2005:Question/4577112019-04-21T22:23:42Z2019-04-21T22:23:42ZUnable to get correct 2θ value from tan2θ = (2*a12)/(a11-a22) by writing as p= A(1,1) - A(2,2) q= 2 * A(1,2) theta = atan (p/q).Please help Unable to get correct 2θ value from tan2θ = (2*a12)/(a11-a22) by writing as
p= A(1,1) - A(2,2)
q= 2 * A(1,2)
theta = atan (p/q) for a (2 x 2) matrix.My code and output are
INPUT >>>>>
% Write down Matrix elements in [A(1,1) A(1,2);A(2,1) A(2,2)] format
Matrix = 'Write down Matrix elements.'
A = input(Matrix)
if ne(A(1,2),A(2,1))
disp('This is a asymmetric matrix')
else
disp('1.This is a symmetric matrix')
% Write down Matrix elements in [A(1,1),A(1,2);A(2,1),A(2,2)] format
p= A(1,1) - A(2,2)
q= 2 * A(1,2)
theta = atan (p/q)
end
OUTPUT >>>>>
Matrix =
'Write down Matrix elements.'
Write down Matrix elements.
[1 2;2 4]
A =
1 2
2 4
1.This is a symmetric matrix
p = -3
q = 4
theta = -0.6435 while correct value from calculator is -0.9272 rad.
Please help me.
Amar Kumarhttps://in.mathworks.com/matlabcentral/profile/authors/15342366-amar-kumartag:in.mathworks.com,2005:Question/4577082019-04-21T22:01:34Z2019-04-21T22:18:47ZAdding Zeros vectors within a matrixI have a 3x3 matrix of values ex
A=[ 1 2 3;
4 5 6;
7 8 9]
I need it to add zeros at certain locations with in the matrix to make a 5x5 with zeros in the 3rd and 4th row and column ex
A2=[1 2 0 0 3;
4 5 0 0 6;
0 0 0 0 0;
0 0 0 0 0;
7 8 0 0 9]
my first attempt was concatenate but I can't figure out how to move the values correctly
newA=[A,zeros(3,2)]
newA_1=[newA;zeros(2,5)]Kevin Smithhttps://in.mathworks.com/matlabcentral/profile/authors/6526383-kevin-smithtag:in.mathworks.com,2005:Question/4577102019-04-21T22:12:35Z2019-04-21T22:17:11Zwhy my picture is 0s ?I work on my project I have a problem
this is my program at the beginning i did it without the function structure then i wanted to put the function structure
as you see my function "my_sct" takes an image like input(image2 result from another program) and must give me an image (look workspace)
the problem is
when I run the program I see 0s and the picture result (output) is black
but when i use image2=imread('image2.jpg') to read the first output picture and i call my fonction "ma_sct(image2)" in commande window i have the correct result
so how to take the image from the first program without going through imread (from workspace)?
Bekhtaoui Abdelhakimhttps://in.mathworks.com/matlabcentral/profile/authors/7850439-bekhtaoui-abdelhakimtag:in.mathworks.com,2005:Question/4550192019-04-08T06:07:42Z2019-04-21T22:15:00ZAHRS sensor fusion IMU input valuesHello Matlab Community,
Firstly, my sincere apologies if this is not the correct place to be posting this question but I really did not know what other website to post to!
I am just wondering if anyone has had any experience with measuring any of the parameters required for tuning the AHRS sensor fusion output? I appear to be obtaining reasonable results for slow movements but faster movements are proving to be troublesome, thus I think it may have something to do with the sensor parameters I am specifying.
The parameters which the ahrs fusion algorithm requires are:
Accelerometer noise - variance of accelerometer signal noise ((m/s^2)^2)
Magnetometer noise - variance of magnetometer signal noise (T^2)
Gyroscope noise - variance of gyroscope signal noise (rad/s)^2
Gyroscope drift noise - variance of gyroscope offset drift (rad/s)^2
Linear acceleration noise - variance of linear acceleration noise (m/s^2)^2
Linear acceleration decay factor (this appears to be dependent on the application/movement velocity)
Magnetic disturbance noise - variance of magnetic disturbance noise (T^2)
Magnetic disturbance decay factor - decay factor for magnetic disturbance
Expected magnetic field strength (I understand this as being location dependant)
Initial process noise - covariance matrix for process noise
https://au.mathworks.com/help/fusion/ref/ahrsfilter-system-object.html
My understanding of IMUs is very basic but I have been trying to get my head around them. I am looking at using the Allan Variance method to determine Angle Random Walk and Rate Random Walk from a static sample of IMU data.
Is my understanding correct in thinking that this will assist me in obtaining values for Gyroscope noise and Gyroscope drift noise?
Any help, input, thoughts or inspiration would be very much appreciated! :)
Kind Regards,
Ben
Benjamin9119https://in.mathworks.com/matlabcentral/profile/authors/14534994-benjamin9119tag:in.mathworks.com,2005:Question/4577072019-04-21T21:53:25Z2019-04-21T22:04:18ZIs there a package in Matlab to solve delay partial differential equations system?Is there a direct method to solve a system of delay partial differential equations in Matlab?
Without time delays we can use pdepe, but is there a similar way to solve the delayed pde?Afnan Alaghahttps://in.mathworks.com/matlabcentral/profile/authors/14788263-afnan-alaghatag:in.mathworks.com,2005:Question/4568912019-04-17T09:48:15Z2019-04-21T21:57:06Zreference to non-existent field solidityhi I have error message in matlab 2017
reference to non-existent field 'solidity'
Error in Tumor(line denisty={stats.solidity};
how can I add reference
what did i miss ?Mohamed Nasrhttps://in.mathworks.com/matlabcentral/profile/authors/15316660-mohamed-nasrtag:in.mathworks.com,2005:Question/4207992018-09-26T08:22:12Z2019-04-21T21:55:30ZWhy does Build fail during Hardware Setup for Simulink Android Support Package for R2018a and R2018bBuild fails during the Hardware Setup with the following failure
Build App
A problem occurred configuring root project 'TestApp'. > No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android *Sruthi Yenugulahttps://in.mathworks.com/matlabcentral/profile/authors/8178414-sruthi-yenugulatag:in.mathworks.com,2005:Question/4576062019-04-21T02:21:46Z2019-04-21T21:54:25Zdifferent font sizes for y labelsHello,
I want to have different font sizes for y-labels. for example in this simple plot, I want to have -2 and 2 in y-axis in font 16 and the rest in font 12:
x = -1:0.01:1;
y = 3*asin(x);
plot(x,y)
set(gca,'Ytick',[-4, -2, 0, 2, 4])Hamidhttps://in.mathworks.com/matlabcentral/profile/authors/8477485-hamidtag:in.mathworks.com,2005:Question/4576872019-04-21T18:51:01Z2019-04-21T21:52:57Zdecimal specification change in a tableI have my data in a table that the user input as a matrix [a 'time', 'temp' b; c,d]. and assigned the first column to time, and sec column be temperature.
a=table(Time,temp)
And the time variable values was converted from min to hours, but how can I make the time variable show to 2 decimal places in the table. mat geekhttps://in.mathworks.com/matlabcentral/profile/authors/9600941-mat-geektag:in.mathworks.com,2005:Question/4576982019-04-21T20:30:41Z2019-04-21T21:51:43ZHow do I create a random row matrix with some fixed positions?Hello everyone,
I want to create a row matrix with some fixed positions. For example,
>> randperm(20)
ans =
11 3 14 5 4 8 13 15 10 6 18 9 20 16 17 7 12 2 19 1
But I want to keep some positions in this array. For example, the first three positions of the array should always be 11 3 and 14, regardless of how much I use the randperm (20) command. How can I do this? It is possible?Abdullah Türkhttps://in.mathworks.com/matlabcentral/profile/authors/12224497-abdullah-turktag:in.mathworks.com,2005:Question/4575212019-04-20T12:04:37Z2019-04-21T21:49:18Zfinding the slope and plotting it in graphi need to find the x,y points and plot those points finding the slope making a line in x,y plane. How can i get it automatically sisir regmihttps://in.mathworks.com/matlabcentral/profile/authors/12162188-sisir-regmitag:in.mathworks.com,2005:Question/4576812019-04-21T18:24:10Z2019-04-21T21:46:26ZHow to plot realtime ECG graph using arduino uno MATLABSorry for broken English
I'm working on a project that need to displaying a realtime ECG graph by using MATLAB and arduino uno. This is my arduino code.
void setup() {
Serial.begin(57600);
}
void loop() {
float voltage = analogRead(A0)*(5.0/1023.0);
Serial.println(voltage);
}
and this is my code in MATLAB
close all
clear all
delete(instrfind(('Port'),('COM5')));
s = serial('COM5','baudrate',57600,'Databits',8);
fopen(s);
ylim([-2,5]);
x = 1:100000;
h = animatedline('MaximumNumPoint',500);
grid on
grid minor
while(1)
for i = 1:100000
voltage = fscanf(s);
y(i)=str2double(voltage);
addpoints(h,x(i),y(i));
drawnow;
end
clearpoints(h)
end
for some reason, an ECG graph didn't show up on a moving graph.
EDIT : an ECG graph is showing up right now, but this ECG graph's width on x-axis is too large.Natthakrit Loe-anurithttps://in.mathworks.com/matlabcentral/profile/authors/15293924-natthakrit-loe-anurittag:in.mathworks.com,2005:Question/4576902019-04-21T19:12:13Z2019-04-21T21:44:19Zhow to plot this ?i have a circle and i want to plot his half radius in the same figure can anyone help me :
angle=linspace(0,2*pi,360);
x=cos(angle);
y=sin(angle);
plot(x,y)
axis('equal')
diadalinahttps://in.mathworks.com/matlabcentral/profile/authors/6918672-diadalinatag:in.mathworks.com,2005:Question/1795992015-02-21T19:58:29Z2019-04-21T21:39:50ZHow can I calculate the slope of a line given two points?I need a function which can output the slope of a 2D line given two points. Ofcourse, I could just use m = (y2-y1)/(x2-x1), however, I have a long list of points/lines which I need to find the slope of and I don't believe this would be the most efficient method.
Something similar to the pdist2(point_a, point_b) function which I've previously used to find the distance between two points would be ideal.
Thanks in advance.
Neal Younghttps://in.mathworks.com/matlabcentral/profile/authors/6204447-neal-youngtag:in.mathworks.com,2005:Question/4576622019-04-21T14:34:21Z2019-04-21T21:37:37ZIm trying to use 4 point gauss quadrature method and this is my code and getting errors any help T^T?Im trying to use 4 point gauss quadrature method and this is my code and getting errors any help T^T?
when i run it im getting statement imcomplete error at line 17
sum=sum+eval(func) * wt(i)
format long
func='(exp(x)*sin(x)/(1+x^2)';
xa=0.0;
xb=3.0;
ngp = 4;
xi(1) = -0.8611363116; wt(1) = 0.3478548451;
xi(2) = -0.3399810436; wt(2) = 0.6521451549;
xi(3) = -xi(1); wt(3) = wt(1);
xi(4) = -xi(2); wt(4) = wt(2);
coeff = (xb-xa)/2.0;
sum = 0.0;
for i=1:ngp
x = (xb+xa)/2.0 + (xb-xa)/2.0 *xi(i);
sum = sum + eval(func)*wt(i);
end
sum = sum * coeff;
[sum]Park Jihoonhttps://in.mathworks.com/matlabcentral/profile/authors/11525431-park-jihoontag:in.mathworks.com,2005:Question/4571532019-04-18T11:19:02Z2019-04-21T21:35:56Zinterpolation of 3d dataI want to interpolate my data with respect to z values means the blank spaces present got filled and z values are interpolated by krigging technique and get result in x y z format but the codes present on the forum interpolates data in the form of bigger matrix and and also do not provide satisfactory results. some code also fails and returns error as data size is too large.
Can anybody pls suggest a code for this. Pls help.....ashwani kumarhttps://in.mathworks.com/matlabcentral/profile/authors/15243249-ashwani-kumartag:in.mathworks.com,2005:Question/4576772019-04-21T18:07:15Z2019-04-21T21:34:16Ztangent at specific pointi plotted parametric curve r(t)=<t , t^2 , 2>, now i have to plot tangent at P(-1 , 1, 2) but i cant figure it out. can you help me please.
t = 0:pi/50:10*pi;
st = t;
ct = t.^2;
figure(1)
plot3(st,ct,repmat(2,1,numel(t)))
hold onKuatra Patilhttps://in.mathworks.com/matlabcentral/profile/authors/15291254-kuatra-patiltag:in.mathworks.com,2005:Question/4576972019-04-21T20:07:22Z2019-04-21T21:32:20Zcalculating line integral code checkso below is my code just wanna know if what i have done is correct
N = 101;
tmin = 0;
tmax = 3;
t = linspace(tmin,tmax,N);
x=2*cos(2*pi*t)+0.4*sin(16*pi*t);
y=4*sin(2*pi*t)+0.2*cos(16*pi*t)+t;
z=0.1*cos(16*pi*t)+t;
r = [ x; y ; z];
dt = t(2)-t(1);
%using central difference approximation
dxdt = (x(3:end)-x(1:end-2))/(2*dt);
dydt = (y(3:end)-y(1:end-2))/(2*dt);
dzdt = (z(3:end)-z(1:end-2))/(2*dt);
drdt = [ dxdt; dydt; dzdt];
n = (N-1)/2; %here we store the number of points that dldt are stored at
dldt = zeros(1,n); %initialise dldt
for i = 1:n
dldt(i) = norm(drdt.*drdt);
end
%integral
l = sum(dldt)*2*dtdulangahttps://in.mathworks.com/matlabcentral/profile/authors/5545365-dulangatag:in.mathworks.com,2005:Question/4569652019-04-17T15:37:15Z2019-04-21T21:31:50ZSimple moving average code for forecasting stock pricesI need code for predicting stock prices in future using simple moving average calculationMegawaty Lestarihttps://in.mathworks.com/matlabcentral/profile/authors/14895494-megawaty-lestaritag:in.mathworks.com,2005:Question/4576942019-04-21T19:45:57Z2019-04-21T21:29:06Zwhat is the difference between rgb2gray and im2bw ?I want to know the difference between the two functions ... arent both convert the rgb image to black and white image ?!Mahmoud Hassanhttps://in.mathworks.com/matlabcentral/profile/authors/13358401-mahmoud-hassantag:in.mathworks.com,2005:Question/4576932019-04-21T19:44:24Z2019-04-21T21:25:37Zplotting help needed (increasing resolution)this is my code how would i increase the resolution of the graph?
N = 101;
tmin = 0;
tmax = 3;
t = linspace(tmin,tmax,N);
x=2*cos(2*pi*t)+0.4*sin(16*pi*t);
y=4*sin(2*pi*t)+0.2*cos(16*pi*t)+t;
z=0.1*cos(16*pi*t)+t;
plot3(x,y,z)dulangahttps://in.mathworks.com/matlabcentral/profile/authors/5545365-dulangatag:in.mathworks.com,2005:Question/4577032019-04-21T21:04:35Z2019-04-21T21:17:52ZPhase Plot - Velocity vs PositionHow can I create a graph of velocity vs position(x' vs x) (phase plot).
Here is the current code I am working with..
function LAB08ex1
m = 1; %mass [kg]
k = 4; %spring constant [N/m]
omega0 = sqrt(k/m);
y0 = 0.1; v0 = 0; %initial conditions
[t,Y] = ode45(@f,[0,10],[y0,v0],[],omega0); % solve for 0<t<10
y = Y(:,1); v = Y(:,2); % time series for y and v
E = (1/2*m*v.^2)+(1/2*k*y.^2); %calculating the energy
figure(1); plot(t,y, 'b+-',t,v,'ro-', t,E, 'gro-'); % retrieve y, v from Y
%-----------------------------------------x
function dYdt = f(t,Y,omega0)
y = Y(1); v = Y(2);
dYdt = [ v ; -omega0^2*y ];
Martin Romerohttps://in.mathworks.com/matlabcentral/profile/authors/14591187-martin-romerotag:in.mathworks.com,2005:Question/4577002019-04-21T20:51:31Z2019-04-21T21:17:50Zi have code in gui and if condition does's work why? please help meM = xlsread('D:\traindata.xls')
N = xlsread('D:\testdata1.xls')
Training_set = M(1:100,2:10)
%specify training set
Target_set = M(1:100,10)
%specify target set
Testing_set = N(1,2:10)
%index=N(:,10)==0002-1;
%specify Testing set
Testing_Target_Set = N(1,11)
%specify Testing set,Target
%X = mapstd(Training_set');
%Y = mapstd(Target_set');
mynetwork = newrb(Training_set',Target_set',0,0.5,100,25)
%newrb(P,T,goal,spread,MN,DF) takes two of these arguments,
%PR x Q matrix of Q input vectors
%TS x Q matrix of Q target class vectors
%goalMean squared error goal (default = 0.0
%spreadSpread of radial basis functions (default = 1.0
%MNMaximum number of neurons (default is Q)
%DFNumber of neurons to add between displays (default = 25)
mynetwork.trainFcn='trainlm';
mynetwork.trainparam.min_grad=0.00000001;
mynetwork.trainparam.epochs=100;
mynetwork.trainparam.ir=0,4;
mynetwork.trainparam.max_fail=20;
%save mynetwork
D=sim(mynetwork,Testing_set')
%simulate network
xlswrite('D:\testdata1.xls',D',2)
%xlswrite(filename, M, sheet) writes matrix M to the specified worksheet sheet in the file filename
if D==1
L='Not Existing'
set(handles.text3,'String',L);
elseif D==2
K='Existing'
set(handles.text3,'String',K);
endmeemee meemeehttps://in.mathworks.com/matlabcentral/profile/authors/15342468-meemee-meemeetag:in.mathworks.com,2005:Question/4531412019-03-28T19:51:59Z2019-04-21T21:17:32Zhow to generate a number in point as bellow?x=(3.25,3.89)+rand*((-0.14,2.92)-(3.25,3.89))?samardin jebranhttps://in.mathworks.com/matlabcentral/profile/authors/14804050-samardin-jebrantag:in.mathworks.com,2005:Question/4577022019-04-21T21:00:10Z2019-04-21T21:16:25Zwho to make code in gui work in any image the user input?[Filename,Pathname]=uigetfile('*.jpg','load image');
name=strcat(Pathname,Filename);
Filename
a=imread(name);
axes(handles.axes1);
imshow(a);
% --- Executes on button press in test.
function test_Callback(hObject, eventdata, handles)
% hObject handle to test (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
M = xlsread('D:\traindata.xls')
N = xlsread('D:\testdata1.xls')
Training_set = M(1:100,2:10)
%specify training set
Target_set = M(1:100,10)
%specify target set
Testing_set = N(1,2:10)
%index=N(:,10)==0002-1;
%specify Testing set
Testing_Target_Set = N(1,11)
%specify Testing set,Target
%X = mapstd(Training_set');
%Y = mapstd(Target_set');
mynetwork = newrb(Training_set',Target_set',0,0.5,100,25)
%newrb(P,T,goal,spread,MN,DF) takes two of these arguments,
%PR x Q matrix of Q input vectors
%TS x Q matrix of Q target class vectors
%goalMean squared error goal (default = 0.0
%spreadSpread of radial basis functions (default = 1.0
%MNMaximum number of neurons (default is Q)
%DFNumber of neurons to add between displays (default = 25)
mynetwork.trainFcn='trainlm';
mynetwork.trainparam.min_grad=0.00000001;
mynetwork.trainparam.epochs=100;
mynetwork.trainparam.ir=0,4;
mynetwork.trainparam.max_fail=20;
%save mynetwork
D=sim(mynetwork,Testing_set')
%simulate network
xlswrite('D:\testdata1.xls',D',2)
%xlswrite(filename, M, sheet) writes matrix M to the specified worksheet sheet in the file filename
if D==1
L='Not Existing'
set(handles.text3,'String',L);
else D==2
K='Existing'
set(handles.text3,'String',K);
end
meemee meemeehttps://in.mathworks.com/matlabcentral/profile/authors/15342468-meemee-meemeetag:in.mathworks.com,2005:Question/4576892019-04-21T19:03:24Z2019-04-21T21:05:07ZHow can I mean multiple matrices, element by element in a n*n cell array?
I've got a data looks like this. size(16*6) cell array. I want to get the average of each columns, but keep the size of each matrice(650*1).Wenyi Xiaohttps://in.mathworks.com/matlabcentral/profile/authors/13762167-wenyi-xiaotag:in.mathworks.com,2005:Question/4561502019-04-13T15:27:20Z2019-04-21T21:01:25ZVariable change (diffeomorphism) in MatlabHi,
I want to know if there's a startand procedure to do the following steps in Matlab:
I have this set of differential equations:
and I want to make the following variable change (a diffeomorphism, in fact):
In order to obtain the first derivatives of the new variables (which I already know):
I know that I can define the first set of like this:
f = @(t,x) [-2*x1+a*x2+sin(x1);
-x2*cos(x1)+u*cos(2*x1)];
And my question is: how to make the variable substitution and the next steps in order to obtain the second set of (,)? Is this even possible in Matlab?
I have tried functions like subs, solver, diff, ode, etc., but I wasn't able to get any results.
Thanks in advance!
BritoJosé Britohttps://in.mathworks.com/matlabcentral/profile/authors/14083109-jose-britotag:in.mathworks.com,2005:Question/4577012019-04-21T20:55:31Z2019-04-21T20:57:15ZHow do I plot data that has a x axis and y axis date?I have data that corresponds to an arrival date and departure date. Basically a pork chop plot. How do I plot the data so that it corresponds to both axes?Alok Virkarhttps://in.mathworks.com/matlabcentral/profile/authors/10812684-alok-virkartag:in.mathworks.com,2005:Question/4576952019-04-21T19:51:46Z2019-04-21T20:55:38Zhow to know if image is rgb?i want to set an if condition to know if the image i am reading is rgb image or not Mahmoud Hassanhttps://in.mathworks.com/matlabcentral/profile/authors/13358401-mahmoud-hassantag:in.mathworks.com,2005:Question/4576992019-04-21T20:46:18Z2019-04-21T20:52:00Zhow can i see the linear variation in the graph?the plot command does plot the graph specificaly. it just shows the x and y axis valuesYashita Singhhttps://in.mathworks.com/matlabcentral/profile/authors/14112491-yashita-singhtag:in.mathworks.com,2005:Question/4576882019-04-21T19:01:26Z2019-04-21T20:47:08ZApplying Boundary Condition to ODE45Hi all,
I have a set of coupled differential equations which are readily arranged to be solved on ode45 in a domain [0 L]. However, all the boundary conditions of the differential equations are given at x=L instead of x=0. I cannot enforce these BCs to my problem using MATLAB. How can i accomplish that ? (I would like to solve set of ODEs using 4th order Runge Katta Method)
Kind RegardsOguz Altunkashttps://in.mathworks.com/matlabcentral/profile/authors/14673472-oguz-altunkastag:in.mathworks.com,2005:Question/4575142019-04-20T10:47:25Z2019-04-21T20:46:55ZHow to crop matrices at the maximal non-NaN values and then center the dataHi all,
I am new to MATLAB and I have the following problem:
I have matrices something like:
H(1).matrix = [1 2 3
3 4 5
3 4 4
6 NaN 7
NaN NaN NaN]
H(2).matrix = [3 4 5
5 6 7
4 4 4
NaN 3 3
NaN 4 4
NaN NaN 7]
H(3).matrix = [3 3 3
2 1 3
NaN 1 2]
Now, I see that these matrices all have 3 columns but different row number, first is 5x3, second 6x3, third 3x3, but also within columns they have different row length with actual numbers and not NaN. I see that the longest rows length where each columns have non NaN values is 2 (in the third matrix, the first row and the second row with all non NaN values). So now I want to crop all the matrices to have size 2x3. Then I want to center all these matrices.
Something like:
H(1).matrix = [1 2 3
3 4 5]
H(2).matrix = [3 4 5
5 6 7]
H(3).matrix = [3 3 3
2 1 3]
Then I want to center the data (remove from each element the average of the column it belongs to).
Thank you in advance!Spresihttps://in.mathworks.com/matlabcentral/profile/authors/12750159-spresitag:in.mathworks.com,2005:Question/4576842019-04-21T18:32:13Z2019-04-21T20:25:15ZWater flow in a bend pipe?Hello Everyone,
I am a beginner in MATLAB. I am trying to simulate water flow in bend converging steel pipe. Friction is considered. Can someone please guide me or tell, where can I find similar tutorials to write the code? I understand the theory part. But I don’t have the knowledge to write in code.
Cheers.Abeed Hassan Nurhttps://in.mathworks.com/matlabcentral/profile/authors/10555567-abeed-hassan-nurtag:in.mathworks.com,2005:Question/384192012-05-15T13:28:17Z2019-04-21T20:23:40ZGet value from popup menu and use it in different functionHi; I am doing GUI which has a popup menu that allow the user to choose from several options, lets say I have three options each one has different values for (I,V,P) current, voltage and power. my coding is like this (for example):
function popupmenu1_Callback(hObject, eventdata, handles)
switch get(handles.popupmenu,'Value')
case 1
I=7;
V=20;
p=130;
case 2
I=5;
V=30;
p=170;
otherwise
end
then I need to use these values in some calculation in pushbutton_callback, which it coding as below(for example):
function pushbutton1_Callback(hObject, eventdata, handles)
what code can I use to get these values from the popup menu ?? I need your help please.Samer Husamhttps://in.mathworks.com/matlabcentral/profile/authors/2804614-samer-husamtag:in.mathworks.com,2005:Question/4576802019-04-21T18:20:15Z2019-04-21T20:10:42ZRearrange matrix and concatenate cellsHi everyone,
I have a 3492x5 matrix with variable names say variable1, variable2,...,variable5. I have been trying to cut this matrix into 12 291x5 cells and rearrange them into a 291x60 matrix. But when I did this, I had error of duplicate variable names. So, I'm wondering if there way to circumvent this? With or without variable names is ok for me since they are not really useful.
Here is the code I used:
filename=datadimer
[m n]=size(filename)
sZ=291;
Numofrows= m/(sZ);
C=mat2cell(filename,sZ*ones(1,Numofrows),size(filename,2));
for i=1:Numofrows
D(:,i)=C(i,:);
end
output=horzcat(D{:});
The input matrix ('filename') contains one row of string and first 16 rows look like this:
Any help will be much appreciated, thank you!
Heathen233https://in.mathworks.com/matlabcentral/profile/authors/5066685-heathen233tag:in.mathworks.com,2005:Question/4572822019-04-18T23:38:55Z2019-04-21T20:02:36Zreindexing a correlation matrixI have a matrix 100x100.
I would like to re-sort the indices of the elements, and re-create the matrix with the new numbering scheme.
showing this as a 3x3 to simplfy my question:
[1 1 1 ; 2 2 2 ; 3 3 3 ]
So that a vector of the element names is 1,2,3,...100.
I want to rename the elements with a new vector, that looks random: 97,5,6... etc
so that I have a new matrix with the new naming arrangement and
so that the value of original element (1,2) will now be the values that was (97,5)
I hope this makes sense. The matrix is not symmetric across the diagonal.
Can someone help me?
thanks
Teena
teena dobbshttps://in.mathworks.com/matlabcentral/profile/authors/10977233-teena-dobbstag:in.mathworks.com,2005:Question/4576482019-04-21T11:34:07Z2019-04-21T19:51:36Zreturn row index of values greater than 0 to a 3 dimensional arrayI have a Matrix A, of m x n dimensions.
I wish to go through each row from left to right and return the index of values greater than 0. I have tried the folowing which returns the column index for the first row which has values. for example row 26.
I have tried the following but I am not getting the outputmatrix with all entries. I fear the entries are being overwritten
A =[2,-4,-0.5,0.34;0.01,4,-0.5,0.34;-10,4,-0.2,0.6;-10,4,-0.2,0.6;-19,15,-0.7,0.6];
% Now we have input matrix A we want to return the col index of each row element greater than 0.
% inputMatrix= A
outputMatrix=zeros(1,[],size(A,1));
for i = 26:size(A(2:end,:),1)
for ij = 1:size(A(2:end,:),2)
[rows, columns] = find(inputMatrix > 0)
outputMatrix=columns;
end
end
A =
2 -4 -0.5 0.34
0.01 4 -0.5 0.34
-10 4 -0.2 0.6
-10 4 -0.2 0.6
-19 15 -0.7 0.6
However I wish to go through each row, and store these column indices in a 3 dimensional array where each page represents the set of column indices from each row of A
Example output is a 3 dimensional array of column indices. - Matrix E
1, 4 (page 1)
1, 2, 4 (page 2)
2, 4 (page 3
2, 4 (page 4)
2,4 (page 5)
I then want to use these column indices to return the value from the corresponding rows of a matrix C and matrix D. Matrix C and D are the same dimentions as A
I then want to multiply C values by D values and return a 3 dimension array of results. - Matrix F
The results will be of the same dimension as Matrix E
Any help appreciated.
Charleshttps://in.mathworks.com/matlabcentral/profile/authors/5506466-charlestag:in.mathworks.com,2005:Question/4571692019-04-18T12:54:14Z2019-04-21T19:49:15ZHow to compute the homography Dear Community,
I have some issue to getting the trasnform image for homography
I want to apply the homography to an image, I do have homography martix from the general formulation
H = R+1/d*n*t'
H = rotation_matrix + t.* Normal
H =
0 -1.0000 0
-0.3420 0 -0.9397
5.9397 5.0000 4.6580
The basic concept of idea is to trying get image from vitrual camera, so the question I that how I can get the image from virtual camera ?
As you can see figure below , I have perspective image but I want to use inverse perspective mapping
Thanking you so much
Sushil Sharmahttps://in.mathworks.com/matlabcentral/profile/authors/14231039-sushil-sharmatag:in.mathworks.com,2005:Question/4576922019-04-21T19:43:54Z2019-04-21T19:43:54ZWhen using the FFT tool from the powergui, a whole cycle is not analyzed despite indicating the number of cycles is 1.The signal being used as the input to the FFT analysis tool is a filtered inverter signal (filtered by hardware and PWM control). I expect the THD to be much less than 48.34% as this is the THD expected from an unfiltered inverter. If I increase the number of cycles to include more of my waveform, the THD increases.
Any suggestions?
Frank Moselyhttps://in.mathworks.com/matlabcentral/profile/authors/6938941-frank-moselytag:in.mathworks.com,2005:Question/4576822019-04-21T18:27:42Z2019-04-21T19:34:13Zinserting image in a tableHey, I want to add an image to the table and then in next cell add it's quantitative measure(found through quality metrics). How can that be done in matlab? Fatima Rashidhttps://in.mathworks.com/matlabcentral/profile/authors/8981413-fatima-rashidtag:in.mathworks.com,2005:Question/4575202019-04-20T11:50:25Z2019-04-21T19:25:31ZTwo graphs at the same time PLEASE HELP
Hello,
I have this code that is used with arduino package
the code will be used to get data from two sensors:
load cell that measures load
displacement sensor that measures displacement
problems:
this code is showing two graphs but only one graph has labels
only one graph is showing data results
this is the code: (please note that i'm new to MATLAB and coding in general)
clear
clc
a=arduino('com3','Uno')
loadcell=addon(a,'ExampleAddon/HX711',{'D2','D3'})
plotTitle1 = 'Load VS Time';
xLabel1 = 'Elapsed Time (s)';
yLabel1 = 'Load (KN)';
legend1 = 'Load Cell 1'
plotTitle2 = 'Displacement VS Time';
xLabel2 = 'Elapsed Time (s)';
yLabel2 = 'Displacement (mm)';
legend2 = 'Displacement Sensor 1'
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
yMax1 = 10000000
yMin1 = 0
yMax2 = 10000000
yMin2 = 0
plotGrid = 'on';
min1 = 0;
max1 = 10000;
min2 = 0;
max2 = 10000;
delay = .001;
time = 0;
data1 = 0;
data11 = 0;
data12 = 0;
data2 = 0;
data21 = 0;
data22 = 0;
count = 0;
subplot(2,4,1)
plotGraph1 = plot(time,data1,'-r')
subplot(2,4,2)
plotGraph2 = plot(time,data2,'-r')
hold on
title(plotTitle1,'FontSize',5);
xlabel(xLabel1,'FontSize',5);
ylabel(yLabel1,'FontSize',5);
axis([yMin1 yMax1 min1 max1]);
title(plotTitle2,'FontSize',5);
xlabel(xLabel2,'FontSize',5);
ylabel(yLabel2,'FontSize',5);
axis([yMin2 yMax2 min2 max2]);
grid(plotGrid);
tic
figure (1)
while ishandle(plotGraph1)
dat1 = read_HX711(loadcell)-1940.225269
count = count + 1;
time(count) = toc;
data1(count) = dat1(1);
set(plotGraph1,'XData',time,'YData',data1);
axis([0 time(count) min1 max1]);
pause(delay);
end
hold on
figure (2)
while ishandle(plotGraph2)
dat2 = readVoltage(a,'A0')*80
count = count + 1;
time(count) = toc;
data2(count) = dat2(1);
set(plotGraph2,'XData',time,'YData',data2);
axis([0 time(count) min2 max2]);
pause(delay);
end
hold off
delete(a);
disp('Plot Closed and arduino object has been deleted');
Ameen Mouazzenhttps://in.mathworks.com/matlabcentral/profile/authors/14732767-ameen-mouazzentag:in.mathworks.com,2005:Question/4573772019-04-19T13:35:12Z2019-04-21T19:11:07ZHow to check Excel sheet data of one with Excel sheet data of another on matlab and print the output on another Excel sheetSo,
I'm reading a list of flights data from an excel sheet called plot:
journeys = readtable('plot.xlsx');
And I have an ATS route givwen by lat10 and lon10:
lat10 = [12.9933,19.0852]; lon10 = [80.1705,72.8752];
I'm reading the flight data and selecting them based on groups (flight numbers) of flights that have 80% of their data within the ats route:
[x10, y10]= mfwdtran(mstruct,lat10,lon10);
X = [x10,fliplr(x10)];
Y = [y10,fliplr(y10)-d];
%Y = [y10,fliplr(y10)-d];
plot(x10,y10,'-','color','m');%plotting ats
hold on;
plot(x10,y10-d,'-','color','m');%only for 2nd and 3rd batch
%plot(x10-d,y10,'-','color','m');%only for first batch
hold on;
%selecting flights--------------
[journeys.x, journeys.y] = mfwdtran(mstruct, journeys.latitude, journeys.longitude); %transform the flights latitude and longitude
in = inpolygon(journeys.x, journeys.y, X, Y);
[groupid, flights] = findgroups(journeys.flight); %assign unique id to each flight and apply to rows of the table
inratio = splitapply(@(in)nnz(in)/numel(in), in, groupid); %ratio of points in polygon to points in flight
selectedflights = flights(inratio >= .8); %for flights that have 70% of their journey in the polygon
% isallin = splitapply(@all, in, groupid); %are ALL points of the flight in the polygon? logical output
% selectedflights = flights(isallin); %list of flights where all points are in the polygon
selectedjourneys = journeys(ismember(journeys.flight, selectedflights), :); %portion of the table with only the selected flights.
%selecting flights--------------
Now, I have a list of ATS routes in an excel sheet called ATS and I want to compare each flight data with each route that they correspond to. If a flight has 80% of its data within the route I want an excel sheet called Match to have the flight number and the ATS route it matches with.
I'm stuck with this problem from a long time now... kindly help please...
I have attached the excel sheets here.harman bhavejahttps://in.mathworks.com/matlabcentral/profile/authors/15243328-harman-bhavejatag:in.mathworks.com,2005:Question/4576852019-04-21T18:37:49Z2019-04-21T19:00:22ZHow to randomly choose 5% of a matrix to be of value 1.I have a 256 x 256 matrix which has value 1 inside a small square 20 x 20 around the center, and zero elsewhere. I need to randomly choose say 5% elsewhere to be 1 also. How do I go about this?
Thank you.Gideon Idumahhttps://in.mathworks.com/matlabcentral/profile/authors/13428802-gideon-idumahtag:in.mathworks.com,2005:Question/14272011-02-16T09:53:30Z2019-04-21T19:00:11ZWhat frustrates you about MATLAB?I love MATLAB. It is so quick and easy to write software to do what you want. It has excellent debugging and profiling tools. It is cross platform, making code easy to share (assuming the other people have forked out for the not-so-cheap license). It has interfaces to other software.
However, there are some things about it that irk me. I'd like to hear from other people what things annoy them about MATLAB.Oliver Woodfordhttps://in.mathworks.com/matlabcentral/profile/authors/1073021-oliver-woodford