How to programmatically access views? - basic4android

I have a lot of views. And I like to have them placed in the program, taking the size of the screen in account. But I have a problem accessing the views in a loop.
Now, I have to take one view at the time:
view1.top = xdip
view2.top = xdip
What I really want to do is:
for c = 1 to 40
view(c).top = ...
next
But I can't get it to work.
Can anyone enlighten me?

See this tutorial.
Here is an example:
For i = 0 To Activity.NumberOfViews - 1
Dim v As View
v = Activity.GetView(i)
v.Top = 30dip
Next

Related

(App Designer) Error using matlab.ui.control.EditField/set.Value (line 96) 'Value' must be a character vector

So I am creating an app to find a value based on several inputs but hit an error as one of the outputs won't show.
This is the app layout
1
The problem is the total cost section won't show the value when I clicked the calculate button. The 'Q Optimal' works just fine.
2
the formula associated with the button on the right side looks like this:
dm=app.MinimumDemandEditField.Value;
dM=app.MaximumDemandEditField.Value;
tm=app.MinimumLeadTimeEditField.Value;
tM=app.MaximumLeadTimeEditField.Value;
r1=app.ReorderLevelEditField.Value;
Et = 0.5*(tm+tM);
vart = 1/12*(tM-tm)^2;
Ed = 0.5*(dm+dM);
vard = 1/12*(dM-dm)^2;
ED = 1/4*(dm+dM)*(tm+tM);
varD = 1/144*(3*(dm+dM)^2*(tM-tm)^2+3*(dM-dm)^2*(tm+tM)^2+(tM-
tm)^2*(dM-dm)^2);
gt = 1/(tM-tm);
fd = 1/(dM-dm);
fD = 1/((dM-dm)*(tM-tm));
f1=app.FixedCostEditField.Value;
c1=app.VariableCostEditField.Value;
h=app.HoldingCostEditField.Value;
s=50*c1;
app.ShortageCostEditField.Value = s
A1=c1+(h/Ed)*(r1-ED);
A2=fD*(r1*(tM-tm)*log(r1/(tM*dm))-(r1^2/dM)+(r1*tM)-
(r1*tm)*log((dM*tM)/r1)-Et);
syms x;
f=(x-r1)*fD;
EB= int(f,r1,dM*tM);
A3=Ed*f1+h*Ed*(fD*((r1^2*tm/2)-(dm*r1/2)*(tM^2-tm^2)+(dm^2/6)*
(tM^3-tm^3)-((r1^3/6*dM)-(dM*r1*tm^2/2)+(dM^2*tm^3/6)))+(fD/18)*
(tM^3-tm^3)*(dM^3-dm^3)-r1*ED+Ed*s*EB);
Q=(1/h)*((Ed*(A1+h*A2-c1)+(h*(ED-r1))));
Eoh=fD*((((r1^3*tM)/2)-(((dm*r1)/2)*(tM^2-tm^2))+(((dm^2)/6)*
(tM^3-tm^3))-((r1^3)/(6*dM))-((dM*r1*tm^2)/2)+((dM^2*tm^3)/6))+
((Q^2)/2*Ed)-(Q*ED/Ed)+((fD/(18*Ed))*((tM^3-tm^3)*(dM^3-dm^3)))+
(Q*r1/Ed)-(r1*ED/Ed));
TC= f1+c1*Q+h*Eoh+s*EB;
app.QOptimalEditField.Value = Q
app.TotalCostEditField.Value = TC
Running this gives the error:
3
I suspect the problem is with my integration process. Have I missed something or is there a better way to do this?
Thank you in advance
Regards,
Kevin Renard
I solved the problem as I noticed that the last error notification states that the input value must be a double scalar and the value of the integration process is not a double scalar, so I revised the integration code into:
syms x;
f=(x-r1)*fD;
EB= double(int(f,r1,dM*tM));
1

Prepping info for a data grid in Swift

I'm making an app that will eventually have a second view controller that displays a grid of information from results of previous days. I've already worked out the app to gather the information I need, which would look as follows:
var s = 0
var d = 0
var h = 0.0
var m = 0.0
var date = NSDate()
So I'm wondering how I can run a function to prep these numbers to be used in a grid in a different view controller later on. There may be no other way to do it than to send it to an outside database, but I'd rather not do that. I think I'm going to want to use either a struct or a class maybe. Maybe I only need a dictionary? I don't know, but I'm going to want to save this information at the end of every day. I could write some psuedo code, but I'm not sure how to do this.
func saveDailyResults() {
??? date = {
s, d, h, m
}
allDates.append(){
date
}
}
I think what I'm looking for would be a way to make some thing like this:
var allResultsFromAllDays = [(2016-08-08, 2, 302, 2.3, 4.5),(2016-08-07, 1, 247, 2.4, 4.7),(2016-08-06, 3, 345, 2.9, 6.5)]
...Which I could append every day when new results come in.
I'd like to be able to later on build something that looks like this from the information.
Thanks for any help you can give me!

tracking position/location in test keyboard & mouse mode (not ppt) with new vizconnect

I can track location fine pre - vizconnect using code like this:-
vrpn7 = viz.add('vrpn7.dle')
posTracker = vrpn7.addTracker('PPT0#WorldViz-PC', 0 )
and then
x,y,z = posTracker.getPosition()
but I now use the new vizconnect e.g.
vizconnect.go( 'vizconnect_hmd_ppt.py' )
I'm wondering what the recommended way is to then access the trackers from my main project '.py' file and particularly when I'm using a keyboard/mouse scenario to simulate movement for during program development.
Any advice would be most welcome.
Thanks
Actually it was pretty straightforward:
first check the names of the trackers using:
print( vizconnect.getTrackerDict() )
it may return something like this
'mouse_and_keyboard_walking'
along with some others e.g. inertia cube, then do
gTracker = vizconnect.getTracker( 'mouse_and_keyboard_walking' )
or
gTracker = vizconnect.getTracker( 'PPT0#WorldViz-PC' )
then periodically call (probably on a callback() ):-
x, y, z = gTracker.getPosition()

How to creates a value in a cell nested in a cell

This seems like a very easy question but I can't seem to work it out. Basically I have a number of cells: Face1, Face2, Scene1, Scene2. Each cell contains a value, for instance, Face1=15, Face2=23, Scene1=46, Scene2=9
Now I would like to group all these cells into one single cell called D, something like this D={Face1,Face2,Scene1,Scene2}. However, when I do this I get D={15,23,46,9}. This is not what I want. I'd like to keep the identity of each cell so when I call D{1,1} I'll get Face1, and when I call Face1, I'll get 15.
Does anyone have a suggestion?
Thanks!
Have you considered using structures? Try this:
D.face1 = 15
D.face2 = 23
You could also do it like this:
D.face(1) = 15
Let me know if that doesn't do it for you.
Probably not the best "solution", but you could do something with eval.
First, create your variables.
Face1 = 15, Face2 = 23, Scene1 = 46, Scene2 = 9
Then, create the cell array containing the variable names, as strings:
D = {'Face1', 'Face2', 'Scene1', 'Scene2'}
You can query their values like this:
>> eval(D{1,1})
Face1 =
15
Too long for a comment:
Looks like you are using arrays, not cells. That is, I think your code looks like this:
Face1 = 15
Face2 = 23
Scene1 = 46
Scene2 = 9
D = {Face1 Face2 Scene1 Scene2}
Which would act as you describe. Now D{1} returns 15.
If you were using "cells", your code would look like this:
Face1 = {15}
Face2 = {23}
Scene1 = {46}
Scene2 = {9}
D = {Face1 Face2 Scene1 Scene2}
This is probably not what you want, but it is the cell solution. Now D{1} returns {15} and D{1}{1} returns 15.
If you want to preserve the names in the composite data D, the a struct is probably the easiest thing. See Fletch's just-posted answer.

Logical indexing of fields within a structure

I have a structure like so:
Basis.FieldsBasisType.fieldsBasisComponents
There are ~13 components to each basis, including 6 asset class IDs.
So, for example
fieldnames(Basis.SalaryIncrease) =
'Constant'
'AWeight'
'AAssetClassID'
'ATimeLag'
'BWeight'
'BAssetClassID'
'BTimeLag'
'CWeight'
'CAssetClassID'
'CTimeLag'
'DWeight'
'DAssetClassID'
'DTimeLag'
'EWeight'
'EAssetClassID'
'ETimeLag'
'FWeight'
'FAssetClassID'
'FTimeLag'
'cap'
'floor'
Now what I want to do is select all unique asset classes used in any basis. I am really struggling to make this neat though, currently I am using:
basisNames = fieldnames(Basis);
requiredSeries=[];
for i = 1:size(fieldnames(Basis),1)
requiredSeries = [requiredSeries;unique(Basis.(basisNames{i}).AAssetClassID)];
requiredSeries = [requiredSeries;unique(Basis.(basisNames{i}).BAssetClassID)];
requiredSeries = [requiredSeries;unique(Basis.(basisNames{i}).CAssetClassID)];
requiredSeries = [requiredSeries;unique(Basis.(basisNames{i}).DAssetClassID)];
requiredSeries = [requiredSeries;unique(Basis.(basisNames{i}).EAssetClassID)];
requiredSeries = [requiredSeries;unique(Basis.(basisNames{i}).FAssetClassID)];
end
requiredSeries = unique(requiredSeries)
Which is really ugly in my opinion. I want to do some kind of string compare to find 'AssetClassID' within the fields, so something like:
field = fieldnames(Basis.(basisNames{1}));
strfind(field,'AssetClassID');
And then use that cell array to logically index 'field' and just grab the data from 'AssetClassID' fields. But I am stuck on making that work.
~cellfun('isempty',strfind(field,'AssetClassID'))
gets me the logical index, how do I apply that to fields and then use it to get values.
Any ideas would be appreciated, I feel there should be a neat way of doing it and I am missing something. Hardcoding those fieldnames seems short sighted as a solution.
#
Edit: I hate myself.
Sorry folks, I came up with a working variant like moments after posting this, apologies for wasting anyones time!
basisNames = fieldnames(Basis);
for i = 1:size(fieldnames(Basis),1)
field = fieldnames(Basis.(basisNames{i}));
field = cell2mat(field(~cellfun('isempty',strfind(field,'AssetClassID'))));
for j = 1:size(field,1)
requiredSeries = [requiredSeries;unique(Basis.(basisNames{i}).(field(1,:)))];
end
requiredSeries = unique(requiredSeries)
end
I was missing a necessary cell2mat earlier which caused the inability to get it to bloody work. Anyway, I'd always like to hear improvements to that but otherwise you can shut this down.
Sorry folks, I came up with a working variant 30 mins or after posting this, popping it down as an answer as per Michelle's suggestion.
basisNames = fieldnames(Basis);
for i = 1:size(fieldnames(Basis),1)
field = fieldnames(Basis.(basisNames{i}));
field = cell2mat(field(~cellfun('isempty',strfind(field,'AssetClassID'))));
for j = 1:size(field,1)
requiredSeries = [requiredSeries;unique(Basis.(basisNames{i}).(a(1,:)))];
end
requiredSeries = unique(requiredSeries)
end
I was missing a necessary cell2mat earlier which caused the inability to get it to bloody work. Anyway, I'd always like to hear improvements to that but otherwise you ignore this entirely :)