Argument to dynamic structure reference must evaluate to a valid field name (helperBluetoothChannelClassification) - bluetooth

Hi im doing a bluetooth project using bluetooth toolbox in matlab, and encountered a problem. So I have been following one of the example from https://www.mathworks.com/help/bluetooth/ug/noncollaborative-bluetooth-le-coexistence-with-wlan-signal-interference.html this error occurred.
ble_wlan_interference
Argument to dynamic structure reference must evaluate to a valid field
name.
Error in helperBluetoothChannelClassification (line 102)
obj.(varargin{idx}) = varargin{idx+1};
Error in ble_wlan_interference (line 58)
classifierObj = helperBluetoothChannelClassification(centralNode,peripheralNode,PERThreshold=50);
At line 102 of helperBluetoothChannelClassification.m is as follows,
methods
% Constructor
function obj = helperBluetoothChannelClassification(varargin)
% Set name-value pairs
for idx = 1:2:nargin
obj.(varargin{idx}) = varargin{idx+1};
end
At line 58 of main code is as follows,
%enable channel classification
enableChannelClassification = true;
if enableChannelClassification
classifierObj = helperBluetoothChannelClassification(centralNode,peripheralNode,PERThreshold=50);
classifyFcn = #(varargin) classifierObj.classifyChannels;
userData = []; % User data needed to be passed to the callback function
callAt = 0; % Absolute simulation time, in seconds
periodicity = 125e-3; % In seconds
scheduleAction(networkSimulator,classifyFcn,userData,callAt,periodicity); % Schedule channel classification
end
I think the centralNode and peripheralNode parameter is not recognizable in helperBluetoothChannelClassification function, but don't know what is a problem.. Thanks :)

Related

Jupyter Notebook HOw can i assign a default value to datepicker and sort the time within the selected date?

I can try to set condition some data that is within the time picker in the datepicker. I got two problem
MY code was
def show_filter_date(start ,end):
print(start_dater.value)
print(end_dater.value)
time_df = (id_one[(id_one['_source.timestampstring']>pd.to_datetime(start))&(id_one['_source.timestampstring']<pd.to_datetime(end))])
#print(time_df.head(20))
# time_df = (id_one[(id_one['_source.timestampstring']>pd.to_datetime(start_dater.value))&(id_one['_source.timestampstring']<pd.to_datetime(end_dater.value))])
time_df.head(20)
layout = widgets.Layout(width='auto', height='40px')
start_dater = widgets.DatePicker(description='Pick a Start Date',disabled=False)
end_dater = widgets.DatePicker(description='Pick an End Date',disabled=False )
#display(widgets.HBox((start_dater, end_dater)))
#display(start_dater)
#display(end_dater)
#id_one.head()
#combine_date = widgets.HBox((start = start_dater, end = end_dater))
#country_selector = widgets.Dropdown(
interact(show_filter_date,start = start_dater , end = end_dater)
everytime i run the code it show Error
"Invalid comparison between dtype=datetime64[ns] and NoneType"
I have tried to assign default value like
start_dater = widgets.DatePicker(description='Pick a Start Date',disabled=False, year = 2020 ,month = 12, day = 1)
but it won't change to 2020/12/01
So, how can I get a value other than null?
I fail in interact for the datepicker in which
A) print(time_df.head(20))
B)
time_df = (id_one[(id_one['_source.timestampstring']>pd.to_datetime(start_dater.value))&(id_one['_source.timestampstring']<pd.to_datetime(end_dater.value))])
time_df.head(20)
Only (A) can be "interact" or "refresh" when I pick a day but not (B)
And for Question 2, when I put time_df.head(20) in the NEXT CELL it does work tho.......
But what i want is to show the result like in time_df
I would appreciate if any help
the id_one is something like
Index _source.hdrrId _source.hdrfId _source.hdrType \
199 1300 1234 1
_source.timestampstring
199 2020-11-06 09:36:04.800
Thanks!
Jeff
I replicated your first error with
id_one = pd.DataFrame(pd.date_range('20200101','20200202'), columns = ['_source.timestampstring'])
This is because you did not set a default value for the DatePicker. The value is None by default hence the error. Here is the fix (value argument is the default value):
start_dater = widgets.DatePicker(description='Pick a Start Date',disabled=False, value = datetime.date(2020,1,1))
end_dater = widgets.DatePicker(description='Pick an End Date',disabled=False, value = datetime.date(2020,2,1))
I cannot replicate your second error. My guess is you put print before the time_df = statement. You need to put the print after the line that calculates time_df

Compile Error: Function Call on Left-hand side of assignment

I got the compile error
"Function call on left-hand side of assignment must return Variant or Object"
Trying to fix an inherited Excel file that calculates various values related to HVAC. The file relies on a couple of Add-In .xla files which contain many functions. I am unable to get results from most of the functions. Either I get numbers that immediately turn to zeros, or I just get #VALUE and #NAME errors.
My VBA skills are somewhat limited as well as my knowledge of the calculations this file is performing.
Function EvapDeltaGrn(altitude, evap_on, tdb_ma, hr_ma, sat_goal, hr_min)
'use to calculate the delta grain when tdb_oa > than sat_goal
EvapDeltaGrn = 0
If tdb_ma = "" Then Exit Function
If hr_ma = "" Then Exit Function
If evap_on Then
If tdb_ma >= (sat_goal) Then 'use evaporative cooling
Enthalpy = Application.Run("'psychrometric functions.xla'!TdbGrainstoEnthalpy", altitude, tdb_ma, hr_ma)
'Range("v14") = enthalpy
EvapDeltaGrn = Application.Run("'psychrometric functions.xla'!TdbEnthalpytoGrains", altitude, sat_goal, Enthalpy)
EvapDeltaGrn = EvapDeltaGrn - hr_ma
EvapDeltaGrn = Round(EvapDeltaGrn, 2)
Else 'evaporative humidification
If hr_ma < hr_min Then EvapDeltaGrn = Round(hr_min - hr_ma, 2)
End If
End If
End Function
The error seems to be at Enthalpy =.

History of previously opened m-files in MATLAB

Is anyway to find history of previously opened m-files in MATLAB R2014b from 2 or 3 months ago? (a list of name of files and paths)
Matlab R2014b stores its recent files in:
%APPDATA%\MathWorks\MATLAB\R2014b\MATLAB_Editor_State.xml
It's a .xml file so it's easy to load and parse with xmlread. I'm not very familiar with xml parsing syntax, but here is how to get information about files (to be adapted to your needs of course):
function [recentFiles] = GetRecentFiles()
%[
% Opens editor's state file
filepart = sprintf('MathWorks\\MATLAB\\R%s\\%s', version('-release'), 'MATLAB_Editor_State.xml');
filename = fullfile(getenv('APPDATA'), filepart);
document = xmlread(filename);
% Get information about 'File' nodes
recentFiles = struct([]);
fileNodes = document.getElementsByTagName('File');
for fni = 1:(fileNodes.getLength())
attributes = fileNodes.item(fni-1).getAttributes(); % Careful, zero based indexing !
for ai = 1:(attributes.getLength())
% Get node attribute
name = char(attributes.item(ai-1).getName()); % Zero based + need marshaling COM 'string' type
value = char(attributes.item(ai-1).getValue()); % Zero based + need marshaling COM 'string' type
% Save in structure
name(1) = upper(name(1)); % Just because I prefer capital letter for field names ...
recentFiles(fni).(name) = value;
end
end
%]
end
This returns a structure like this:
recentFiles =
1x43 struct array with fields:
AbsPath
LastWrittenTime
Name
NB: I've tried to type in matlab command window matlab.desktop.editor.*, but seems there's nothing regarding recent files (anyway there are a lot of interesting things to manipulate the editor from the command line)
Last answer waIs really helpful. I've just modified it to read and open the recent tab files. This works on Matlab R2013a:
function [recentFiles] = recover_tabs()
%[
% Opens editor's state file
filepart = sprintf('MathWorks\\MATLAB\\R%s\\%s', version('-release'), 'MATLAB_Editor_State.xml');
filename = fullfile(getenv('APPDATA'), filepart);
document = xmlread(filename);
% Get information about 'File' nodes
recentFiles = struct([]);
fileNodes = document.getElementsByTagName('File');
for fni = 1:(fileNodes.getLength())
attributes = fileNodes.item(fni-1).getAttributes(); % Careful, zero based indexing !
for ai = 1:(attributes.getLength())
% Get node attribute
name = char(attributes.item(ai-1).getName()); % Zero based + need marshaling COM 'string' type
value = char(attributes.item(ai-1).getValue()); % Zero based + need marshaling COM 'string' type
% Save in structure
name(1) = upper(name(1)); % Just because I prefer capital letter for field names ...
recentFiles(fni).(name) = value;
end
end
% loop to access files in the tab history
for j=1:length(recentFiles)
arquivo = [recentFiles(j).AbsPath '\' recentFiles(j).Name];
% if exists, then open
if exist(arquivo, 'file') == 2
open(arquivo);
end
end
%]
end
Base in the answer by CitizenInsane, but for any Matlab version.
To find the .xml file in any Matlab version, use prefdir:
>> prefdir
ans = '/Users/user/Library/Application Support/MathWorks/MATLAB/R2018a'
MATLAB_Editor_State.xml will be stored there. Therefore the fuction would be:
function [recentFiles] = GetRecentFiles()
% Opens editor's state file
filepart = sprintf([ prefdir '/MATLAB_Editor_State.xml']);
filename = fullfile(getenv('APPDATA'), filepart);
document = xmlread(filename);
% Get information about 'File' nodes
recentFiles = struct([]);
fileNodes = document.getElementsByTagName('File');
for fni = 1:(fileNodes.getLength())
attributes = fileNodes.item(fni-1).getAttributes(); % Careful, zero based indexing !
for ai = 1:(attributes.getLength())
% Get node attribute
name = char(attributes.item(ai-1).getName()); % Zero based + need marshaling COM 'string' type
value = char(attributes.item(ai-1).getValue()); % Zero based + need marshaling COM 'string' type
% Save in structure
name(1) = upper(name(1)); % Just because I prefer capital letter for field names ...
recentFiles(fni).(name) = value;
end
end
In R2018b you can increase the Most recently used file list in Preferences > Editor/Debugger. I like the methods above, but they do not work if you're working across machines (e.g., using Github). I coded a solution that uses the modified file date from the machine, instead of relying on MATLAB itself.

Why can't I directly assign to object properties using multiple return values from a method?

Based on this question I've coded the following which throws a compilation time error:
Here is the code:
43. Currency currency = new Currency()
44. (currency.rate_one, currency.time_one) = getDateAndRate()
My method with two return values:
def getDateAndRate(){
Date date = new Date()
double rate = getRate();
return [rate, date]
}
Error thrown
expecting '}', found ',' # line 44, column 26.
(currency.rate_one, currency.time_one) = getDateAndRate()
^
Try this instead
def (rate, time) = getDateAndRate()
currency.rate_one = rate
currency.time_one = time
There is a trick I learned only recently myself and that is to combine multiple assignment and with:
with (currency) {
(rate_one, time_one) = getDateAndTime()
}

How to find data between two values

I am trying to find the data between two values. I am using this code in a GUI programme, the starting_value and ending_value which you can see in the code below are selected from 2 listboxes in a previous part of the code.
% --- Executes on button press in CalculateIntensity.
function CalculateIntensity_Callback(hObject, eventdata, handles)
% hObject handle to CalculateIntensity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Trapz function
starting_value = getappdata(0,'StartValue');
ending_value = getappdata(0,'EndValue');
StartingValue = str2mat(starting_value)
EndingValue = str2mat(ending_value)
A = getappdata(0,'XYarray')
data_found = A(A(:,[1,2]) > StartingValue & A(:,[1,2]) < EndingValue)
I found help on:
http://www.mathworks.com/matlabcentral/answers/8556-how-to-find-vector-elements-between-two-values-efficiently
However the
data_found = A(A(:,[1,2]) > StartingValue & A(:,[1,2]) < EndingValue)
part of the code wont work for me, I think starting_value and ending_value are strings so I tried converting it to a matrix but I get the error:
Error using <
Matrix dimensions must agree.
Error in MichelleLaycockGUImainwindow>CalculateIntensity_Callback (line 119)
data_found = A(A(:,[1,2]) > StartingValue & A(:,[1,2]) < EndingValue)
an example of data used is:
A =
1.0e+03 *
0.1660 1.1570
0.1664 0.4650
0.1668 0
0.1672 1.0200
0.1676 1.0110
0.1680 1.0200
0.1684 1.0640
0.1688 1.1100
0.1692 1.0370
0.1696 1.0050
0.1700 1.0750
0.1704 1.0850
0.1708 1.1310
0.1712 1.0630
0.1716 1.0370
0.1719 1.1070
0.1724 1.1450
I'm not really sure where I'm going wrong, any help would be greatly appreciated as it's all I need to complete my work. Thanks in advance!
As some of the values in my data vary rather than just decreasing or increasing the greater than or equal to method I was originally trying to use did not work. So rather than using the loop to get the data between the two points selected I went with a different method.
I use[~,indx1]=ismember(StartingValue,A,'rows') this finds the row number of the selected data and then I use this information to extract the data between and including the selected data.
Here is the full code I used to do this:
starting_value = getappdata(0,'StartValue');
ending_value = getappdata(0,'EndValue');
StartingValue = str2num(starting_value);
EndingValue = str2num(ending_value);
A = getappdata(0,'XYarray');
[~,indx1]=ismember(StartingValue,A,'rows');
[~,indx2]=ismember(EndingValue,A,'rows');
arrayfortrapz = A(indx1:indx2,1:2); %array of data including and between selected data
I hope this of some help to anybody that may run into a similar issue.

Resources