https://au.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-02-28T06:41:32Ztag:au.mathworks.com,2005:Question/5080532020-02-28T06:39:25Z2020-02-28T06:41:32ZHow to get real time data from teensy 3.5/6 to matlabHi, I want to get real time data from teensy 3.5 or 3.6 to matlab
we are using spi connection between teensy and adxl345
also, we are using arduino IDE and teensyduino
our arduino code is
#include <SparkFun_ADXL345.h> // SparkFun ADXL345 Library
ADXL345 adxl = ADXL345(10);
void setup(){
Serial.begin(9600); // Start the serial terminal
Serial.println("SparkFun ADXL345 Accelerometer Hook Up Guide Example");
Serial.println();
adxl.powerOn();
adxl.setRangeSetting(16);
adxl.setSpiBit(0);
adxl.setActivityXYZ(1, 0, 0);
adxl.setActivityThreshold(75);
adxl.setInactivityXYZ(1, 0, 0);
adxl.setInactivityThreshold(75);
adxl.setTimeInactivity(10);
adxl.setTapDetectionOnXYZ(0, 0, 1);
adxl.setTapThreshold(50);
adxl.setTapDuration(15);
adxl.setDoubleTapLatency(80);
adxl.setDoubleTapWindow(200);
adxl.setFreeFallThreshold(7);
adxl.setFreeFallDuration(30);
adxl.InactivityINT(1);
adxl.ActivityINT(1);
adxl.FreeFallINT(1);
adxl.doubleTapINT(1);
adxl.singleTapINT(1);
}
void loop(){
int x,y,z;
adxl.readAccel(&x, &y, &z);
Serial.print(x);
Serial.print(", ");
Serial.print(y);
Serial.print(", ");
Serial.println(z);
}Yonghoon Choihttps://au.mathworks.com/matlabcentral/profile/authors/17662155-yonghoon-choitag:au.mathworks.com,2005:Question/5080542020-02-28T06:39:45Z2020-02-28T06:39:45ZGUI handles reference to non-existent field 'timer'After initiating the code below the GUI appears, but if I try to press any of the buttons I get a Reference to non-existent field 'timer' error. I have changed the GUI visibility to on, and am still getting this error. See code and full error text below.
____________________________________________________
ERROR
_______________________________________________________________
Reference to non-existent field 'timer'.
Error in Boid_GUI>Start_Callback (line 91)
start(handles.timer)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Boid_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Boid_GUI('Start_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
_________________________________________________________________________
CODE
____________________________________________________________
function varargout = Boid_GUI(varargin)
% BOID_GUI MATLAB code for Boid_GUI.fig
% BOID_GUI, by itself, creates a new BOID_GUI or raises the existing
% singleton*.
%
% H = BOID_GUI returns the handle to a new BOID_GUI or the handle to
% the existing singleton*.
%
% BOID_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BOID_GUI.M with the given input arguments.
%
% BOID_GUI('Property','Value',...) creates a new BOID_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Boid_GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Boid_GUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Boid_GUI
% Last Modified by GUIDE v2.5 27-Feb-2020 23:38:53
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Boid_GUI_OpeningFcn, ...
'gui_OutputFcn', @Boid_GUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Boid_GUI is made visible.
function Boid_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Boid_GUI (see VARARGIN)
% Choose default command line output for Boid_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Boid_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
handles.N = 20; % define the number of boids
% initialize boids position and velocity
boid.pos = 5000.*rand(handles.N,2);
boid.vel = [150.*rand(handles.N,1) 10.*rand(handles.N,1)];
boid_plotter(boid,handles) % call the function to plot the boids in the GUI window
% create timer object
handles.timer = timer;
set(handles.timer,'TimerFcn',{@my_callback_fun,handles},'Period',.1)
set(handles.timer,'ExecutionMode','fixedRate','UserData',boid)
% --- Outputs from this function are returned to the command line.
function varargout = Boid_GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in Start.
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
start(handles.timer)
% --- Executes on button press in Stop.
function Stop_Callback(hObject, eventdata, handles)
% hObject handle to Stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
stop(handles.timer)
% --- Executes on button press in Reset.
function Reset_Callback(hObject, eventdata, handles)
% hObject handle to Reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
stop(handles.timer)
% initialize boids position and velocity
boid.pos = 5000.*rand(handles.N,2);
boid.vel = [150.*rand(handles.N,1) zeros(handles.N,1)];
set(handles.timer,'UserData',boid)
% --- Executes on slider movement.
function slider3_Callback(hObject, eventdata, handles)
% hObject handle to slider3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider3_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function slider4_Callback(hObject, eventdata, handles)
% hObject handle to slider4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider4_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function slider5_Callback(hObject, eventdata, handles)
% hObject handle to slider5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider5_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function my_callback_fun(obj,event,handles)
% get data
boid = get(obj,'UserData');
% move boids
[boid.pos,boid.vel] = move_all_boids(boid.pos,boid.vel,handles);
% plot boids
boid_plotter(boid,handles)
% update data
set(obj,'UserData',boid);
%-----------------------------------------------------------------------
function boid_plotter(boid,handles)
h = axis(handles.axes1);
plot(boid.pos(:,1),boid.pos(:,2),'o')
axis([0 5000 0 5000]);
set(gca,'XTick',[],'YTick',[])
hold on
for i=1:size(boid.vel,1)
plot([boid.pos(i,1) boid.pos(i,1)+boid.vel(i,1)],...
[boid.pos(i,2) boid.pos(i,2)+boid.vel(i,2)],'r')
end
hold off
function [pos,vel] = move_all_boids(pos,vel,handles)
h = findobj(gcf,'Style','slider');
behavior_strength = get(h,'Value');
% cycle through all boids
for i=1:size(pos,1)
% calculate behaviorial velocity maneuvers
separation = 1*behavior_strength{1}*avoid(pos,i,200);
allignment = 5*behavior_strength{2}*match_vel(vel,i);
cohesion = .5*behavior_strength{3}*center_of_mass(pos,i);
% update boid
vel(i,:) = vel(i,:) + separation + allignment + cohesion;
% keep velocity magnitude constant (150)
vel(i,:) = 150*(vel(i,:)/norm(vel(i,:)));
% update position and restrict the values within the plot axis (mod.m, % modulus function)
pos(i,:) = mod(pos(i,:) + vel(i,:),5000);
end
%---------------------------------------------------------------
function v1 = center_of_mass(pos,i)
% function to move each boid towards the precieved
% center of mass of the rest of the flock
% percieved center of mass
pc = (sum(pos,1) - pos(i,:))/(size(pos,1)-1);
% move the boid towards the center by 1%
v1 = 0.01*(pc - pos(i,:));
%---------------------------------------------------------------
function v2 = avoid(pos,i,dist)
% function to move each boid away from other boids
v2 = [0 0];
for k = 1:size(pos,1)
if k ~= i
if norm(pos(i,:) - pos(k,:)) < dist
v2 = (pos(i,:) - pos(k,:))-v2 ;
end
end
end
%---------------------------------------------------------------
function v3 = match_vel(vel,i)
% function to match each boids velocity with near birds
% note: same as rule one but with velocity rather than position
pv = (sum(vel,1) - vel(i,:))/(size(vel,1) - 1);
v3 = 0.01*(pv - vel(i,:));4007williamhttps://au.mathworks.com/matlabcentral/profile/authors/17662380-4007williamtag:au.mathworks.com,2005:Question/2793352016-04-16T16:38:28Z2020-02-28T06:36:53ZEquation From a simple feedforward neural networkHi every one,
I'm working on a code which provide the full equation from a FeedForword Neural Network (FNN) in a text file consedering all weights and biases :
I have already the trained FNN stored (the "net" file), the first step is to see if I have the same result when using :
load Net17 net
input = [12,0.2]; % an input example
output = net(input');
and when I do this :
IW = net.IW{1,1} ;
b1 = net.b{1};
b2 = net.b{2};
LW = net.LW{2,1};
y = b2 + LW * tansig( IW * input' +b1 );
Note that my net is a simple FNN with one hiden layer; 2 input neurons, 17 hiden neurons (for this example) and one output neuron.
I don't know if a did a mistake but the result is diffrent :
output = 353.3947
y = -7.8709
any suggestions ???
Thanks...
References :
http://fr.mathworks.com/help/nnet/ug/multilayer-neural-network-architecture.html?refresh=true
http://fr.mathworks.com/help/nnet/ref/setwb.html
http://fr.mathworks.com/help/nnet/ref/tansig.html
http://fr.mathworks.com/matlabcentral/answers/165233-neural-network-how-does-neural-network-calculate-output-from-net-iw-net-lw-net-bMohamed BENALLALhttps://au.mathworks.com/matlabcentral/profile/authors/4815493-mohamed-benallaltag:au.mathworks.com,2005:Question/5075212020-02-25T18:58:37Z2020-02-28T06:36:29ZMATLAB App Designer - Plotting image on uifigureI'm attempting to plot a grayscale image on a uifigure (not on the main UIAxes) using the following code:
f = uifigure('Name','Please draw your desired region of interest with the mouse.');
im = uiimage(f);
im.ImageSource = (app.Images(:,:,app.CurrentImageIndex));
My overall goal here is to allow the user to draw a rectangle to specify a region of interest. I wasn't able to do this on the UIAxes - I'm not sure that there's a way to draw on them, so I'm creating a uifigure instead. The problem is that the ImageSource property must be an mxnx3 color data matrix. So I have two questions: Why does this property need a 3d matrix to work? Is there an alternative way to plot a grayscale image on a uifigure? Any help would be greatly appreciated.Sam Nadjarihttps://au.mathworks.com/matlabcentral/profile/authors/10765317-sam-nadjaritag:au.mathworks.com,2005:Question/5080492020-02-28T05:53:07Z2020-02-28T06:34:58ZWhat is the best way to Enhance RGB images ? I am working on an image processing project and some of the photos that I am using need some brightness/Contrast or color enhancement. For example in the photo below what is the best way to perform the enhancement if I want to be able to have clearer signs so the alforithm can detect the texts and shapes. Roozbeh Khhttps://au.mathworks.com/matlabcentral/profile/authors/12396892-roozbeh-khtag:au.mathworks.com,2005:Question/5080522020-02-28T06:31:18Z2020-02-28T06:31:18ZLSTM code example is giving different accuracy?https://in.mathworks.com/help/deeplearning/examples/classify-sequence-data-using-lstm-networks.html
i am running same code but getting an accuracy of 93.27 . Can somebody explain why?kchttps://au.mathworks.com/matlabcentral/profile/authors/5751317-kctag:au.mathworks.com,2005:Question/5080512020-02-28T06:04:06Z2020-02-28T06:30:20ZExplicit solution not foundI tried to solve the following differential equation, but it's not giving any solution. Can anyone help?
syms V(x) x a b td L dD ga
dx=((td.*x)/(L-dD)).*exp(ga*((td.*x)/(L-dD))-(L-dD));
DV=diff(V);
ode=diff(V,x,2)==b-((a/dx)*V);
cond1 = V(0) == 0;
cond2 = DV(0) == 0;
conds = [cond1 cond2];
ySol(x) = dsolve(ode,conds);
ySol = simplify(ySol)
Output:
Warning: Explicit solution could not be found.
> In dsolve (line 201)
Swarnav Mukhopadhyayhttps://au.mathworks.com/matlabcentral/profile/authors/9780006-swarnav-mukhopadhyaytag:au.mathworks.com,2005:Question/5080462020-02-28T05:06:45Z2020-02-28T06:28:28ZIssue regarding bandpass filteringDear all,
I have signal covers frequency ranging from 0.001 to 7.5 Hz and want to extract 0.01- 0.1 Hz frequency band. I have applied the following code in matlab 2019.
bpFilt = designfilt('bandpassfir','FilterOrder',25, ...
'CutoffFrequency1',0.01,'CutoffFrequency2',0.1, ...
'SampleRate',15);
x_filtered=filter(bpFilt,data_hz);
x_delay_compensated= filtfilt(bpFilt,data_hz);
I can't able to extract the signal using above code. If I change band range 1-5 Hz then i can able to extract it ?
Could you please help me what could be done if I want to get a signal ranging from 0.01-0.1 Hz?
Thanking you
Vijay
Vijay Kumarhttps://au.mathworks.com/matlabcentral/profile/authors/11311529-vijay-kumartag:au.mathworks.com,2005:Question/5080452020-02-28T04:57:49Z2020-02-28T06:27:37Zequally spaced array of complex numbers How to create an equally spaced vector from -2i to 2i with increment of 0.01?Romiohttps://au.mathworks.com/matlabcentral/profile/authors/10838202-romiotag:au.mathworks.com,2005:Question/5073482020-02-25T03:03:16Z2020-02-28T06:27:22Zhelp to discretization using a loopHi,
I am a matlab learner. Now I would like to discretization a differential equation to get a simple method.
dC/dz=CA*CB/(1+CB);
x=zeros(1:26);
x(1:13)=CA(1:13);
x(14:26)=CB(1:13);
r(1)=(CA(3)-CA(1))/2+CA(2)*CB(2);
...
r(13)=(CA(15)-CA(13))/2+CA(14)*CB(14);
r(14)=(CB(3)-CB(1))/2+0.5*CA(2)*CB(2);
...
r(26)=(CB(15)-CB(13))/2+0.5*CA(14)*CB(14);
Could anyone help me write a loop for this? Thank you so much.
Jiakang Chenhttps://au.mathworks.com/matlabcentral/profile/authors/10749872-jiakang-chentag:au.mathworks.com,2005:Question/5080442020-02-28T04:48:40Z2020-02-28T06:19:35ZHow to save a uitable as either a png, jpeg, pdf, excel?Hi!
I have uitable that I created that changes the background color of the data row depending if certain conditions are met. I am now trying to export that out of matlab and save it as either a png, jpeg, pdf, excel table (I'm not picky). It is very important to maintain the background color of the table rows as it is what gives them utility. I'm not sure how to go about this, working with R2019b. camicathttps://au.mathworks.com/matlabcentral/profile/authors/17213017-camicattag:au.mathworks.com,2005:Question/5078512020-02-27T08:48:11Z2020-02-28T06:19:28ZFWHM and area under curve calculationsobjective: 1.calculation of FWHM for multiple pulses in a single waveform
2.calculation of the area present under each pulse in data waveform containing multiple pulses
(without using any toolbox in matlab) using generalised logical statements.SHANTANU KSHIRSAGARhttps://au.mathworks.com/matlabcentral/profile/authors/14328513-shantanu-kshirsagartag:au.mathworks.com,2005:Question/5074742020-02-25T15:13:39Z2020-02-28T06:17:05Zcreating and using serial objects within a classHi, i've created a script where i am setting up a serialport object in one function and then sending commands to the serial object in another.
however the object is empty when i try to talk to it any ideas where i'm going wrong here?
the functions are being called from an app.
classdef XY_STAGE_TEST
%UNTITLED Summary of this class goes here
% Detailed explanation goes here
properties (Access = public)
XY_port
XY_Comm
p;
b;
db;
sb;
par;
fcon;
Serial;
State;
S_port;
end
methods (Access = public)
function app = XY_STAGE_TEST(port,braud, databits, sbit, parity, fcontrol)
app.p=strcat('COM',num2str(port));
app.b=braud;
app.db=databits;
app.sb =sbit;
app.par = parity;
app.fcon = fcontrol;
end
function [app,State,msg] = XYSerialConnectPort(app) %setup port and check port is availible
if ismember(app.p,serialportlist)
msg = strcat(app.p,' port found');
try
app.S_port = serialport(app.p,app.b,'DataBits',app.db,'StopBits',app.sb,'Parity',app.par,'FlowControl',app.fcon);
State = true;
msg = strcat(msg,' and Connected');
catch
State = false;
msg = strcat(msg,' but I cannot talk to XY comm port, is it already in in use?');
end
else
State = false;
msg = strcat(app.p,' port can not be connected to are you sure it is or not already in use')
end
%disp (State)
end
function [app,State,msg] = connect(app)
[app,State,msg]= app.XYSerialConnectPort();
end
function [app] = home(app)
%app.S_port=serialport(app.p,app.b,'DataBits',app.db,'StopBits',app.sb,'Parity',app.par,'FlowControl',app.fcon) % if i create the serial object here it works fine
%Home Y '430401002201'
str= '430401002201';
command=sscanf(str,'%2X')
write(app.S_port,command,'int8');
end
function close(app)
delete(app.XY_Comm)
delete(app.S_port)
disp 'closed'
end
end
endRobert Crawfordhttps://au.mathworks.com/matlabcentral/profile/authors/4780923-robert-crawfordtag:au.mathworks.com,2005:Question/5074282020-02-25T11:44:44Z2020-02-28T06:08:09Zlog function returning complex answers where there should be noneSo I have a 22*9 matrix. with 22 regions and 9 years. I am doing a decomposition analysis where need to calculate different factors contribution to the overalla change in total carbon emissions, between each set of years, for each region.
For some reason however, my code returns complex answers (for both Ln(r,m) and DeltaCO2CI) when there should only be real numbers. Can't figure out what i have done wrong?
here's the problematic part of the code:
DeltaCO2CI=zeros(21,9);
for r=2:22
for m=2:9
Ln(r,m)=(co2r(r,m)-co2r(r,m-1))./(log(co2r(r,m)-co2r(r,m-1))));
DeltaCO2CI(r,m)=sum((Ln(r,m)).*log(CI(r,m)./CI(r,m-1))));
end
end
Sandra Levinhttps://au.mathworks.com/matlabcentral/profile/authors/2813718-sandra-levintag:au.mathworks.com,2005:Question/5080502020-02-28T06:00:17Z2020-02-28T06:00:17ZAccessing EM wave field in Phased Array toolboxI am using the phased array toolbox and have worked through several Matlab examples such as the End to End Radar System (https://www.mathworks.com/help/phased/gs/end-to-end-radar-system.html). I would like to know how the EM wave is being modelled during propagation from the radiator to target and then from target to collector? I know on the collector the wavefront can be specified to be plane, meaning all the collected signals are summed coherently as plane wave fields. Is there a command I can use or method for extracting these plane wave fields during their propagation between the radaitor to target and target to collector?
collector = phased.Collector('Sensor',antenna,...
'PropagationSpeed',physconst('LightSpeed'),'Wavefront','Plane',...
'OperatingFrequency',4e9);
In summary, I would like to know how the EM waves are being modelled when they are propagating in the radar enviornment and if there is a command in the phased array toolbox for extracting the EM waves at specific instances during their propagation.
Thank You.Sean Farrellhttps://au.mathworks.com/matlabcentral/profile/authors/16060303-sean-farrelltag:au.mathworks.com,2005:Question/4075022018-06-26T14:21:15Z2020-02-28T05:53:07ZIncompatible gcc version with mexI run Ubuntu 18.04. When I try to compile files with mex, I get the error message saying that mex requires version 6.3.x of gcc, whereas the default gcc version on 18.04 is 7.3.
So far so good, I try to get my hands on an older version of gcc, but all i can find through the supported repositories is gcc version 6.4. The only way I seem to be able to get specifically version 6.3 is by manually compiling and installing gcc, but frankly, I do not want to go down that rabbit hole.
I have seen your <https://se.mathworks.com/matlabcentral/answers/48313-why-doesn-t-matlab-support-newer-gcc-versions answer> regarding why you don't always support the latest gcc version, but can you please at least offer support for the latest version of gcc 6 (i.e. 6.4.x)?Andréas Sundströmhttps://au.mathworks.com/matlabcentral/profile/authors/4609475-andreas-sundstromtag:au.mathworks.com,2005:Question/4662602019-06-10T05:26:18Z2020-02-28T05:51:10Z How to find the Statistical Properties(Mean, Standard Deviation, Skwness and Kurtosis) of image?I = imread('C:\Users\Annalakshmi\Desktop\file\bse_gray_250.png');
offsets0 = [zeros(40,1) (1:40)'];
glcms = graycomatrix(I,'Offset',offsets0)
glcm = graycomatrix(I,'Offset',[2 0;0 2])
stats = graycoprops(glcm)Anu Ghttps://au.mathworks.com/matlabcentral/profile/authors/5879981-anu-gtag:au.mathworks.com,2005:Question/5073642020-02-25T05:06:58Z2020-02-28T05:45:26ZUndefined Variable Error in FunctionFor my homework we have to plot a second order differential equation. I believe I have the basic structure of how to do this down but I keep getting and error about one of my variables.
I keep getting an error saying that x is not defined, however I can't seem to find a place where I would define it as the second order equation is acceleration and in terms of velocity. Is there a place where I can define x without messing up the rest of my code or a way to get MATLAB to ignore it.
v0 = 10; %initial velocity
theta = 45; % degrees
m = 1; %kg
x0 = 0; %Initial x
y0 = 0; % Initial y
g = 9.8; %gravity
tspan = [0 ; .0001 ; .3]; %seconds
[t,x] = ode45(@f,tspan,x0);
function fix = f(t,x)
x = X(1);
v = X(2);
c = 0;
fix = [ v ; -c*v*cos(theta)/1*(sqrt(v*cos(theta)+v*sin(theta)))^(p-1) ];
end
Sarah Petersonhttps://au.mathworks.com/matlabcentral/profile/authors/13317079-sarah-petersontag:au.mathworks.com,2005:Question/5073512020-02-25T03:51:47Z2020-02-28T05:43:21ZVALIDATION CRITERION MET DURING TRAINING OF VGG19
Is this network is overfitting? There is condition called "validation criterion met " arises and stop the training process why? what is the solution for that? Is this is possible to train a neural network using transfer learning(vgg19) by having single 8gb ram cpu ? Is there any chance that this 8 gb ram will lead to these kind of errors ?
Thank You in advance.. Deepika Bhttps://au.mathworks.com/matlabcentral/profile/authors/17029048-deepika-btag:au.mathworks.com,2005:Question/2715002016-03-04T15:59:43Z2020-02-28T05:41:33ZSolve the Riccati eqn symbolicallyHi folks
I want to solve the Riccati equation symbolically. For example, I have 4 state variables in Q and 2 inputs in R lqr weights.
Q=diag([q11 q22 q33 q44]);
R=diag([r11 r22]);
The Riccati equation is
A'*P+P*A-P*B*(inv( R ))*B'*P+Q=0
A:4x4 matrix , B:4x2 matrix
I want to solve that equation with respect to "P" matrix variable.
In other words, the answer should be like P=(...) and that should contain the variables q11 q22 q33 q44 and r11 r22. Is there anyone who can help?
I appreciate all answers,
Thank you ENDhttps://au.mathworks.com/matlabcentral/profile/authors/4105906-endtag:au.mathworks.com,2005:Question/5080482020-02-28T05:32:37Z2020-02-28T05:32:37ZDelay diferential equation solution with dd23
For first part, I use this code in Live editor:
%Solución ejercicio 7.29 i)
f=@(t,x,z)[z(1,2)^2+z(2,2)^2-6*z(1,1)-8*z(2,3);x(1)*(2*z(2,2)-x(1)+5-2*z(1,3)^2)];%Defino variables de estado, retrasos z y declaro ecuación diferencial principal
lags=[0.5 0.2 0.1];%Defino retardos
f2=@(t,x)[t,exp(t)];
tspan=[0 1.5];%Intervalo de tiempo
sol=dde23(f,lags,f2,tspan);
axis([0 1.5 -10 10])
legend('x','y')
For the second part, I am confused because the condition abut replace the term x^2(t-0.1) for x'(t-0.1) I can't code it. I tried this but I have one error
%Solución ejercicio 7.29 ii)
f=@(t,x,z)[z(1,2)^2+z(3,2)^2-6*z(1,1)-8*z(3,3);x(1)*(2*z(3,2)-x(1)+5-2*z(2,3))];%Defino variables de estado, retrasos z y declaro ecuación diferencial principal
%x=x(1), x'=x(2), y=x(3)
%z1=0.5 z2=0.2 z3=0.1
lags=[0.5 0.2 0.1];%Defino retardos
f2=@(t,x)[t,exp(t),1];
tspan=[0 1.5];%Intervalo de tiempo
sol=dde23(f,lags,f2,tspan);
axis([0 1.5 -10 10])
legend('x','y')
Error using dde23 (line 223)
Derivative and history vectors have different lengths.
Please help me thanksMaria Cuellarhttps://au.mathworks.com/matlabcentral/profile/authors/17370401-maria-cuellartag:au.mathworks.com,2005:Question/4378222019-01-01T09:14:42Z2020-02-28T05:30:36ZI am solving 20 nonlinear equation using fsolve to find 20 variables' value. But i previously know one of variable's value. That variable is x(17) in eqn F(17). x(17)=1200. Based on this fixed variable i want to find remaining variables' value. function F = root16d(x)
Qs_ref=0;
Pw_ref=0.322;
F(1) = -0.5*((x(1)*x(2))-(x(3)*x(4)))-Qs_ref; %Qr=0.5*((x(5)*x(8))-(x(7)*x(6))
F(2) = 0.5*((x(1)*x(4))+(x(3)*x(2)))+0.5*((x(5)*x(6))+(x(7)*x(8)))+Pw_ref;
%% Algebric Equation
F(3) = 0.5*((x(1)*x(9))+(x(3)*x(10)))+0.5*((x(1)*x(4))+(x(3)*x(2)))-0.5*((x(11)*x(15))+(x(12)*x(16)));
F(4) = 0.5*((x(1)*x(2))-(x(3)*x(4)))+0.5*((x(1)*x(10))-(x(3)*x(9)))+0.5*((x(11)*x(16))-(x(12)*x(15)));
%% SS of Tr line
delta=0.1049;
Rl=0.02; we=2*pi*60;
Xl=0.5; wb=2*pi*60;
Xc=0.75*0.5;
EB=1;
Ebq=EB*cos(delta);
Ebd=EB*sin(delta);
%
F(5) = -(Rl*wb/Xl)*x(9)-we*x(10)-(wb/Xl)*x(13)+(wb/Xl)*(x(1)-Ebq);
F(6) = we*x(9)-(Rl*wb/Xl)*(x(10))-(wb/Xl)*x(14)+(wb/Xl)*(x(3)-Ebd);
F(7) = (wb*x(9)*Xc)-(we*x(13));
F(8) = (wb*x(10)*Xc)+(we*x(13));
%% two aglebric equation
Xtg=0.3;
F(13)= x(1)-x(11)+(Xtg*x(16));
F(14)= x(3)-x(12)-(Xtg*x(15));
F(15)= x(15)-x(4)-x(9);
F(16)= x(16)-x(2)-x(10);
%% Power flow equation for DC capacitor placed between GSC and RSC
C=50*14000e-6;%C=1;
F(17)= (100e6*((0.5*(x(5)*x(6)+x(7)*x(8)))+(0.5*(x(11)*x(15)+x(12)*x(16))))/(-C*1200));%100e6**x(17)
%% State Space model of Generator Turbine shaft model
Dt=0; Ht=4.29;
Dtg=1.5; Hg=0.9; Ktg=0.15;
Xm=3.95279; Tw=0.322/(0.75);
Wbase=2*pi*60; Te=0.5*Xm*(((x(4)+x(6))*x(8))-((x(2)+x(8))*x(6)));
F(18)= ((-Dt-Dtg)/(2*Ht))*x(18)+((Dtg/(2*Ht))*x(19))-(x(20)/(2*Ht))+(Tw/(2*Ht));
F(19)= ((Dtg/(2*Hg))*x(18))+((-Dt-Dtg)/(2*Hg))*x(19)+(x(20)/(2*Hg))-(Te/(2*Hg));
F(20)=(Ktg*Wbase)*x(18)-(Ktg*Wbase)*x(19);
%% State Space model of DFIG
Rs = 0.00488; Wb= 2*pi*60%2*pi*60;
Rr = 0.00549; We= 2*pi*60;%2*pi*60;
Xls = 0.09231; Wr= 2*pi*60*x(19);%2*pi*60*x(19)
Xlr = 0.09955;
Xm = 3.95279;
Xss = Xls+Xm; Xrr = Xlr+Xm;
F(9)=x(2)*((Xm^2*(We - Wr))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (We*(Xlr + Xm)*(Xls + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm)) - x(8)*((We*Xm*(Xlr + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Xm*(Xlr + Xm)*(We - Wr))/(Xlr*Xls + Xlr*Xm + Xls*Xm)) + (Wb*x(1)*(Xlr + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Wb*Xm*x(5))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Rs*Wb*x(4)*(Xlr + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) + (Rr*Wb*Xm*x(6))/(Xlr*Xls + Xlr*Xm + Xls*Xm)
F(10)= x(6)*((We*Xm*(Xlr + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Xm*(Xlr + Xm)*(We - Wr))/(Xlr*Xls + Xlr*Xm + Xls*Xm)) - x(4)*((Xm^2*(We - Wr))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (We*(Xlr + Xm)*(Xls + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm)) + (Wb*x(3)*(Xlr + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Wb*Xm*x(7))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Rs*Wb*x(2)*(Xlr + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) + (Rr*Wb*Xm*x(8))/(Xlr*Xls + Xlr*Xm + Xls*Xm)
F(11)=x(2)*((We*Xm*(Xls + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Xm*(Xls + Xm)*(We - Wr))/(Xlr*Xls + Xlr*Xm + Xls*Xm)) + x(8)*((We*Xm^2)/(Xlr*Xls + Xlr*Xm + Xls*Xm) - ((Xlr + Xm)*(Xls + Xm)*(We - Wr))/(Xlr*Xls + Xlr*Xm + Xls*Xm)) + (Wb*x(5)*(Xls + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Wb*Xm*x(1))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Rr*Wb*x(6)*(Xls + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) + (Rs*Wb*Xm*x(4))/(Xlr*Xls + Xlr*Xm + Xls*Xm)
F(12)=(Wb*x(7)*(Xls + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - x(6)*((We*Xm^2)/(Xlr*Xls + Xlr*Xm + Xls*Xm) - ((Xlr + Xm)*(Xls + Xm)*(We - Wr))/(Xlr*Xls + Xlr*Xm + Xls*Xm)) - x(4)*((We*Xm*(Xls + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Xm*(Xls + Xm)*(We - Wr))/(Xlr*Xls + Xlr*Xm + Xls*Xm)) - (Wb*Xm*x(3))/(Xlr*Xls + Xlr*Xm + Xls*Xm) - (Rr*Wb*x(8)*(Xls + Xm))/(Xlr*Xls + Xlr*Xm + Xls*Xm) + (Rs*Wb*Xm*x(2))/(Xlr*Xls + Xlr*Xm + Xls*Xm)
chirag rohithttps://au.mathworks.com/matlabcentral/profile/authors/7055363-chirag-rohittag:au.mathworks.com,2005:Question/5080472020-02-28T05:19:09Z2020-02-28T05:23:14ZMeasure angles between one fixed and one variables linesHello,
I have a fixed line and a line with the same origin that rotates with respect to the fixed line. I measure the angles between the two lines per iteration using the code
for j = 1:timestep(i) * periodpl(i)
lonecljdnew(j) = lonecljd(jdate + j / timestep(i)) - lonecljd(jdate) + 360 .* ( lonecljd(jdate + j / timestep(i)) < lonecljd(jdate) );
end
Here, timestep(i), periodpl(i) and jdate are given numbers.
However, it produces valid output only when the variable line, lonecljd(jdate + j / timestep(i)), forms angles with the fixed line, lonecljd(jdate), less than or equal to 360 degrees. How to measure angles exceeding 360 degrees, i.e., when the variable line makes several full cicrles around the fixed one?
Thank you in advance!Asatur Khurshudyanhttps://au.mathworks.com/matlabcentral/profile/authors/2949402-asatur-khurshudyantag:au.mathworks.com,2005:Question/400192012-05-31T21:55:47Z2020-02-28T05:00:26Zstoring data from functionHi,
I have this code in my function file: [sound, freq] = wavread(file)
and for some reason sound and freq are not being stored in the workspace. What am I doing wrong?Jonathanhttps://au.mathworks.com/matlabcentral/profile/authors/3331998-jonathantag:au.mathworks.com,2005:Question/5073882020-02-25T08:19:43Z2020-02-28T04:58:58ZHow to add arrow to a line (like quiver)Hello,
Consider I have a smple line. I want to add arrow (for example 4 arrows to this line) and show it in plot. Is it possible?
x = [0,1,2,3];
y=[ 4,4,4,4]
plot(x,y)
ThnaksTorkanhttps://au.mathworks.com/matlabcentral/profile/authors/12096592-torkantag:au.mathworks.com,2005:Question/5036212020-02-04T15:41:26Z2020-02-28T04:57:29Zhow to add datatip to a line object inside an UIAxes?Hi,
I am trying to show datatips when clicked for some simple lines inside an UIaxes. However this warning occurs even when I move my mouse over the axes:
Warning: Error occurred while executing the listener callback for event MouseMove defined for class
matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipInteraction:
Error using hgconvertunits
The reference object is invalid.
Thanks!Mario Schwarzhttps://au.mathworks.com/matlabcentral/profile/authors/9693000-mario-schwarztag:au.mathworks.com,2005:Question/5061372020-02-18T09:58:32Z2020-02-28T04:57:10Za simple line plot in an uiaxes in AppDesigner leads to error messagesI am working in AppDesigner and I create an uiaxes where i simply plot some lines. When the mouse is near the plotted line i get a bunch of errormessages in the command window:
Warning: Error occurred while executing the listener callback for event MouseMove defined for class
matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipInteraction:
Error using hgconvertunits
The reference object is invalid.
Error in getpixelposition
Error in getpixelposition
Error in getpixelposition
Error in brushing.select.translateToContainer
Error in matlab.graphics.interaction.uiaxes.Datatips
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Error in
matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipInteraction/actionevent
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.InteractionBase
Error in matlab.graphics.interaction.graphicscontrol.GenericControl/process
Error in matlab.graphics.interaction.graphicscontrol.layoutable.LayoutableControl/process
Error in matlab.graphics.interaction.graphicscontrol.AxesControl/processMario Schwarzhttps://au.mathworks.com/matlabcentral/profile/authors/9693000-mario-schwarztag:au.mathworks.com,2005:Question/2703292016-02-27T16:47:54Z2020-02-28T04:44:54ZHow to select the components that show the most variance in PCAI have a huge data set that I need for training (32000*2500). This seems to be too much for my classifier. So I decided to do some reading on dimensionality reduction and specifically into PCA.
From my understanding PCA selects the current data and replots them on another (x,y) domain/scale. These new coordinates don't mean anything but the data is rearranged to give one axis maximum variation. After these new coefficients I can drop the cooeff having minimum variation.
Now I am trying to implement this in MatLab and am having trouble with the output provided. MatLab always considers rows as observations and columns as variables. So my inout to the pca function would be my matrix of size (32000*2500). This would return the PCA coefficients in an output matrix of size 2500*2500.
The help for pca states:
_Each column of coeff contains coefficients for one principal component, and the columns are in descending order of component variance._
In this output, which dimension is the observations of my data? I mean if I have to give this to the classifier, will the rows of coeff represent my datas observations or is it now the columns of coeff?
And how do I remove the coefficients having the least variation? And thus effectively reduce the dimension of my dataFarazhttps://au.mathworks.com/matlabcentral/profile/authors/5127186-faraztag:au.mathworks.com,2005:Question/1561522014-09-25T13:52:29Z2020-02-28T04:42:41Zhow to extract the area, perimeter for the object present in the image?i m in need to measure the features like area, perimetr , length, width of the segmented image.... when i used bwarea to find area, it calculates the total area of the image but it wont gives the area of the object in the image....my segmented image is attached below....i want area bounded inside the green boundary and red region the image that image i attached.
<</matlabcentral/answers/uploaded_files/18583/3_Outlines.bmp>>souhttps://au.mathworks.com/matlabcentral/profile/authors/5484225-soutag:au.mathworks.com,2005:Question/5080042020-02-27T22:20:57Z2020-02-28T04:37:24ZPlotting selected columns of a matrixI have a 32x1544 matrix.
I want to plot the 1st 8 column as plot1, 2nd 8 columns as plot2 and the 3rd 8 columns as plot3.
So all the 3 seperate plots are 32x8 2D-plot
Please advise. ThanksFarhan Khttps://au.mathworks.com/matlabcentral/profile/authors/17625341-farhan-ktag:au.mathworks.com,2005:Question/5080422020-02-28T04:36:08Z2020-02-28T04:37:05ZHow do I solve the convergence problem in Simscape?
The layout is a modification of the example layout 'Steam Rankine Cycle' in Simscape.
When I run to find the steady solution first, I get a series of errors saying:
I have tried to remove the priority setting from all variables, but it fails to give me a converged steady solution.
Any recommendations on how to tackle this problem?
Thank you in advance.
Jin Young Heohttps://au.mathworks.com/matlabcentral/profile/authors/2777909-jin-young-heotag:au.mathworks.com,2005:Question/5077362020-02-26T17:38:33Z2020-02-28T04:32:38ZUsing m script in matlabHow can I move to a specific position in a text file and write a text there?
example:volatile real32_T AutoWakeUpBalncDlyT_T_Pt = 3.0F;/* Delay time to distinguish to go to sleep. */
before (AutoWakeUpBalncDlyT_T_Pt) I have to add Rom_
expected :volatile real32_T Rom_AutoWakeUpBalncDlyT_T_Pt = 3.0F;/* Delay time to distinguish to go to sleep. */ANAND VISHALhttps://au.mathworks.com/matlabcentral/profile/authors/5433311-anand-vishaltag:au.mathworks.com,2005:Question/4462142019-02-21T11:24:25Z2020-02-28T04:31:33ZInitial working folder resets to C:\Windows\System32MATLAB 2018b always starts with the working folder C:\Windows\System32. I've changed the preferences so that the initial working folder should be the last working folder. I've also cleared the "Start in" path from the MATLAB shortcut. I've checked the matlab.settings-file, and it seems that the "LastFolderPath" always resets to C:\Windows\System32 on the startup. When installing 2018b I copied my old preferences from 2016b version. I suspect this might have caused the problem. Kaarle Kupiainenhttps://au.mathworks.com/matlabcentral/profile/authors/1644894-kaarle-kupiainentag:au.mathworks.com,2005:Question/5080412020-02-28T04:31:13Z2020-02-28T04:31:13ZI have downloaded Matlab by university link successfully but it doesn't work at allMy mac is MAC OS CATALINA VERSION 10.15.3.
I downloaded the matlab but it is not working ?
Taif Almutairihttps://au.mathworks.com/matlabcentral/profile/authors/17622321-taif-almutairitag:au.mathworks.com,2005:Question/5080402020-02-28T04:18:56Z2020-02-28T04:18:56ZCan anyone please explain that what each command is showing in the following program? How to select the dimesions? As well as recommend something to study the loops.X=x(2:21); (what is the meaning of x(2:21))?
Y=y(2:21);
M=zeros([20,10]);
for i=1:20
for j=1:10
if j==1
M(i,j)=1;
elseif j==2
M(i,j)=x(i);
elseif j==3
M(i,j)=y(i);
elseif j==4
M(i,j)=x(i)^2;
elseif j==5
M(i,j)=y(i)^2;
elseif j==6
M(i,j)=x(i)*y(i);
elseif j==7
M(i,j)=x(i)^2*y(i);
elseif j==8
M(i,j)=y(i)^2*x(i);
elseif j==9
M(i,j)=x(i)^3;
else
M(i,j)=y(i)^3;
end
end
end
X=X';zelda lambdahttps://au.mathworks.com/matlabcentral/profile/authors/9179792-zelda-lambdatag:au.mathworks.com,2005:Question/5080382020-02-28T03:50:27Z2020-02-28T04:14:08ZHow to solve a system of polynomial equations?Hello everyone,
Let us say that I have that following system of polynomial equations:
2 + 26*x - 18*y - 7*x*y + 28*y² = 0
472 + 2*w + 3*x - 3*y - 2*x² + 5*y² = 0
18 + 2*x + 3*z - 17*x*z - 2*x² = 0
3 - 2*w - 8*x + 3*w*x + 6*x² = 0
How could I solve this problem with matlab?
Any suggestions?
Thanks in advance!Gabriel Coelhohttps://au.mathworks.com/matlabcentral/profile/authors/4441958-gabriel-coelhotag:au.mathworks.com,2005:Question/5079762020-02-27T19:23:11Z2020-02-28T04:12:43ZHow can I interpolate with function interp2 with longitude and latitudes coordinatesHi!
I have this:
X= [-97.3750 -97.1250]
Y= [22.3750 22.3750]
lat=[22.3623 22.3623]
lon=[-97.3500 -97.3500]
V=[0.1085 .0693]
Vq= interp2(X,Y,V,lon,lat,'lineal');
Sintax Error:
Error using griddedInterpolant
Interpolation requires at least two sample points in each dimension.
Error in interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 128)
F = makegriddedinterp({X, Y}, V, method,extrap);
**Why can't I interpolate? Thanks!!Ana Teresa Escobar Ortizhttps://au.mathworks.com/matlabcentral/profile/authors/17498949-ana-teresa-escobar-ortiztag:au.mathworks.com,2005:Question/1483602014-08-14T07:09:50Z2020-02-28T04:08:05ZInterfacing ADS1115 with raspberry pi in matlabI am trying to get a signal sampled by ADC interfaced with raspberry pi via Matlab. The code is as follows,
mypi = raspi
i2cadc = i2cdev(mypi,'i2c-1','0x48')
act_val=0;
for i= 1:1:1000
writeRegister(i2cadc,1,hex2dec('C3E3'),'uint16'); %single shot 860fps (Config register)
while (value ~= 50147) % wait until the MSB of conversion register has changed)
[value]=readRegister(i2cadc,1,'uint16');
end
[value1]=readRegister(i2cadc,0,'int16'); %(conversion register)
act_val1(i)=value1;
act_val(i)=(value1*4.096)/32767.0;
end
figure;plot(act_val1);
figure;plot(act_val);
My input signal is 50 Hz sine, I have configured the ADS115 at 860fps and i am reading the signal from channel A0. The signal which is read from the conversion register is just some random noise rather than the actual signal. I don't know what is the problem with the code, but hardware wise the connections are intact and correct. Kindly let me know the issue with this code.Subash chandarhttps://au.mathworks.com/matlabcentral/profile/authors/5430219-subash-chandartag:au.mathworks.com,2005:Question/732012013-04-23T08:39:36Z2020-02-28T03:57:57Zhow to display two graphs in separate figure windows using plot command?i use a matlab program for my project. There i want to produce two graphs at different instances. But the second graph replaces the 1st graph when that command is executed.. i want both to be displayed in separate window. I dont want both graphs in same window (using "subplot"). Is it possible in matlab?Harish Balagahttps://au.mathworks.com/matlabcentral/profile/authors/2657630-harish-balagatag:au.mathworks.com,2005:Question/5078632020-02-27T09:56:11Z2020-02-28T03:57:43Zinterfacing oled with c2000 launchpadHello,
We are facing issue with interfacing the OLED with F28379D launchpad, please guide us.
Regards,
Pramod.Pramod Kumar I Mhttps://au.mathworks.com/matlabcentral/profile/authors/17148057-pramod-kumar-i-mtag:au.mathworks.com,2005:Question/5074602020-02-25T14:17:21Z2020-02-28T03:55:39ZPlotting multiple graphs in one figureHello, I am new to matlab and have written a code to create a custom fit for data. I am hoping to plot multiple data sets with this fit in one figure. Currently, this code runs but it creates an individual plot for each data set, which is not what I want. Also, I am having difficulty with the legend formatting. I want to make each line a different color and label as y1,y2,y3... but what I have been currently doing is not working. Thank you.
%% create figure for each data set
w={}; %to collect coefficient values
y=Y(:,1);
hold all
for i=1:1:u %where u is the final column of y values
y=Y(:,i);
[xData, yData] = prepareCurveData( X, y );
ft = fittype( 'a*exp(-b*x)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.893783889527977 0.298767974365371];
% Plot fit with data.
figure( 'Name', ['y',sprintf('%d',i)] );
% Fit model to data.
[fitresult{i}, gof(i)] = fit( xData, yData, ft, opts );
disp(fitresult)
hold all % from here downwards is where I find difficulty plotting correctly
for j=1:1:u
h = plot( fitresult{i}, xData, yData);
legendInfo{i}=[num2str(i),'=y'];
legend(legendInfo);
v =coeffvalues(fitresult{i});
w =[w v];
end
hold off
% Label axes
xlabel X
ylabel y_i
grid on
end
hold offamy gravensteinhttps://au.mathworks.com/matlabcentral/profile/authors/17183515-amy-gravensteintag:au.mathworks.com,2005:Question/5080392020-02-28T03:55:10Z2020-02-28T03:55:10ZCONFUSION MATRIX RESULTS INFORMATION FOR PRETRAINED NEURAL NETWORK
I got this confusion matrix for pretrained vgg19 model after the validation process, what are all the information obtained by this confusion matrix ?
how can we identified that this model is good for classification of multiclass based on this confusion matrix?
Thank you for your response in advance.Deepika Bhttps://au.mathworks.com/matlabcentral/profile/authors/17029048-deepika-btag:au.mathworks.com,2005:Question/5005542020-01-16T10:09:02Z2020-02-28T03:53:11ZObjective and Nonlinear Constraints in the Same Function for genetic algorithmHi, I have a question about how to reduce computational time of GA with non-linear constraints and mixed-integer variables.
I have referered to the page "Objective and Nonlinear Constraints in the Same Function" and seems that this is exactly what I want to solve.
https://jp.mathworks.com/help/optim/ug/objective-and-nonlinear-constraints-in-the-same-function.html?lang=en#d117e7977
However, in this page, it is stated that Because of the way ga calls nonlinear constraint functions, the technique in this example usually does not reduce the number of calls to the objective or constraint functions.
Actually, I tried the solution to my codes and it did not work.
Since there is almost the same question (below) but without answer, it would be appreciated if you could give me advice.
(Reletated question)
Share information between objective and constraint function with genetic algorithm
https://jp.mathworks.com/matlabcentral/answers/443733-share-information-between-objective-and-constraint-function-with-genetic-algorithmYohei Shibatahttps://au.mathworks.com/matlabcentral/profile/authors/8197767-yohei-shibatatag:au.mathworks.com,2005:Question/5080352020-02-28T02:50:32Z2020-02-28T03:51:41ZHow to plot this differential equationy=2xC-(C^2)/4
with multiple lines on same graph
any value for C and x except 0AFhttps://au.mathworks.com/matlabcentral/profile/authors/16113221-aftag:au.mathworks.com,2005:Question/5078582020-02-27T09:39:19Z2020-02-28T03:49:38Z sampling time issue with c2000 F28379d and matlab simulation. hello,
I am implementing a simulation for hardware in matlab. The simulink file is running at sampling time at 1e-4. At this sasmpling frequency, I am losing some samples, and ADC not taking total samples of voltage signal values above 2khz. Then i try to dump the simulink file at a sampling time 1e-6, it showing some error, and it not reaching the data to target also. the error like it showing is" code replacement library must provide entries for semaphore/mutex creation."I am running an induction motor at 1e-4 sampling time with an open loop. Now I am sensing the voltage signal at a switching frequency of 10 kHz through ADC in hardware. As per my design of the voltage sensing circuit will give a peak to peak 3.3v or less. But, input to the ADC and output of ADC is not matching. Then I thought of running my simulation at sampling time 1e-6 because of my sampling time at least ten times the switching frequency. Then I check the ADC through a function generator at sampling time 1e-4 of pulse generation wave with a duty of 50%. The rate of the pulse wave is initially 1khz later I varied the frequency, but the output of my ADC has not matched. Please tell me where I made a mistake in the simulation, what I do to run the simulation entirely at both sampling time 1e-4 and 1e-6.
The below-attached results are an image of my simulation at 1e-4.
mahesh reddy pundruhttps://au.mathworks.com/matlabcentral/profile/authors/13893116-mahesh-reddy-pundrutag:au.mathworks.com,2005:Question/5080372020-02-28T05:00:00Z2020-02-28T03:48:06ZWhy does "setVariable" in Simulink Test not update variables?I'm using "setVariable" to update a variable in a test harness. I'm using the command
evalin('base', 'y_coordinate')
in a "From Workspace" block to load the variable into Simulink.
However, in R2019b the variable doesn't seem to get updated. Why does this happen?MathWorks Support Teamhttps://au.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:au.mathworks.com,2005:Question/5080122020-02-27T23:38:51Z2020-02-28T03:26:04Zconverting a vector to matrixI'm doing practice questions, and I am stuck. If the vector is x=[9,4,0,7] and i want to create a Matrix with 4 rows (the original vector, the recipricol, the factorial of the originals using my own code i already wrote, and the factorial using matlab's factorial function) while also putting ruler lines above and below the outputs. How the heck does one do this?Charlotte Reedhttps://au.mathworks.com/matlabcentral/profile/authors/17213943-charlotte-reedtag:au.mathworks.com,2005:Question/5080262020-02-28T01:51:01Z2020-02-28T03:22:33Zissues with Cholesky decompositionHello guys. I have a question with Cholesky decompostion. I am running a code for MCMC sampling in high dimensional linear regression. You know that this means I have to perform Cholesky decomposition many times. In some cases I get error by non-positive definite covariance matrix. However, when I rerun the code again with same dataset, the problem can disappear. I really have no clue why this happens. Any suggestions? Thanks!Yu Baihttps://au.mathworks.com/matlabcentral/profile/authors/16648977-yu-baitag:au.mathworks.com,2005:Question/4123952018-07-27T11:59:11Z2020-02-28T03:19:53ZWhy is there no code folding option for live scrip editor?I have currently version 2017b and overall I'm very happy with the live editor. I like being able to put scientific code with a lot of background information and then create a .pdf report from that. But there are 2 things which are not implemented well:
* There is no code folding option to hide repeating, not so important parts
* The .pdf export does not wrap the code lines to fit A4 pages, so most of the time it cuts it to the side (In contrast it works well for text)
* No option to change font sizesSebastian Schmidhttps://au.mathworks.com/matlabcentral/profile/authors/11326345-sebastian-schmidtag:au.mathworks.com,2005:Question/5080302020-02-28T02:31:32Z2020-02-28T03:18:36ZHelp storing data from while loopI am working on an assignment where I need to save the iteration and the root value for each iteration under a single column matrix I am going to put my code underneath. Please let me know if you can help!
x = [0:0.1:2];
% Set bounds for graph
F = 5*sin(x/4)-1.3;
% Create function for graph
plot(x,F),grid
% Display function
[bracket,x] = ginput(2)
% Let user select two bounds from graph
x_lo = min(bracket)
x_up = max(bracket)
f = @(x) 5*sin(x/4) - 1.3
error = 10;
iter = 0
while error > 1e-4
iter = iter+1
tr = x_lo - f(x_lo)*(x_up-x_lo)/(f(x_up) - f(x_lo))
fr = f(tr)
if sign(fr) == sign(f(x_up))
x_up = tr
else
x_lo = tr
end
error = abs(fr);
end
root = tr
John Furmanhttps://au.mathworks.com/matlabcentral/profile/authors/17300722-john-furman