|
I have an array in the main class:
static void Main(string[] args)
here is the array
Contact[] contactArray;
contactArray = new Contact[2];
contactArray[0] = contact1;
contactArray[1] = contact2;
Contact is a class of it's own and contact 1 has been initialized in the main class.
I need to access this array from a UI class and iterate through it and display the content
I'm stuck. thanks.
|
|
|
|
|
One way to do this is to create a View Model class, and have all global data accessible via the view model. In the XAML file, you set the DataContext element to a static instance of the View Model class.
You create all UI classes in the View Model class, not in main(). When creating a UI class, one of the parameters to the constructor should be the VM instance.
A Google on "WPF View Model" and "XAML DataContext" should give you plent of examples of this technique.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
|
From time to time, I have faced the same requirement. I found that the simplest solution was to promote the object to class scope and mark it as both static and public. Thereafter, other classes reference it as Program.MyObject.
For example:
static public Contact[] contactArray;
static void Main(string[] args)
contactArray = new Contact[2];
contactArray[0] = contact1;
contactArray[1] = contact2;
In your form, you refer to contactArray as follows.
Contact Contact1 = Progarm.contactArray[0];
|
|
|
|
|
Ok i am really struggling with this, if any one can help it'd be appreciated (lanuguage c#):
Example string:
[[[['1'],'2'],'3'],[[[[[[['0015,15','bob'],'99'],'98'],'97','96'],'95'],[[[['Ra','sa','pa'],'01-01-2001','bob ',''],'']],'0045',''],'1',[['300','80','Ends, Here','0015',''],['300','84','Start','0015','']],'','0045','N','0045','']]
Requirement:
I need a function to split the above string into some sort of indexable array/tree using:
[] as start/stop node delimiters
, as a field delimiter within the node
The string is dynamic and could have multiple values in each child and have different amounts of childs/subchildren. I see this as being similar to parsing xml/creating a tree but i may be wrong....
Example usage (using above string):
if i were to reference node 1,3 i would return a '1' ([[[['1']..]..]..]
if i were to reference node 1,2,4 i would return '97','96'[ [,,[,,[,,]]] [[[[[[[..]..]..]'97','96']..]..]..] ..]
So basically i need something that will dynamically create the tree structure that i can ref through co-ordinates.
If your wondering - this is a webserver response so i have no control over what is returned, this is needed to allow me to identify a set of values for the applicable page section.
Any help appreciated - i am especially after code that i can copy paste to get a solution
|
|
|
|
|
This looks very much like something that would be trivially represented in LISP !!
A recursive descent parser would handle this pretty easily.
You need to define your "output" representation.
I'd suggest a structure like a class that could be used like a LISP cons cell:
class Node
{
public string Value;
public Node Head = null;
public Node Tail = null;
public bool HasValue = false;
public Node(string value, Node tail=null)
{
Value = value;
HasValue = true;
Tail = tail;
}
public Node(Node head=null, Node tail=null)
{
Head = head;
Tail = tail;
}
}
Value and Head should be properties that keep the HasValue correct in their setters. (Left as an exercise.)
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
Another possibility that occurs to me is to begin with a regular expression to split the string at the square bracket delimiters. Bear in mind, of course, that the square brackets must be escaped, since they are, themselves, regular expression tokens. The substrings would inhabit a Matches collection, of which each substring would them be a well formed CSV, easily split by way of string.split.
|
|
|
|
|
The regular expression ([[]]|[^[]]+) will tokenize the input to a Matches collection of the square brackets and everything else.
It is tempting to include the comma in this process, but there are two cases in the example provided where the comma is inside (unescaped) of the quoted (single quotes) string. This is not well formed CSV.
Further, some of the "everything else" strings either begin or end with the comma depending on their location in the ultimate tree structure.
It isn't apparent that this would be any more efficient than just scanning the input string during the recursive descent parsing.
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
I suggested a regex just to stir the pot a bit. Since regular expression parsing can consume quite a bit of memory, and aren't necessarily "efficient," you are probably right about recursive descent parsing being more efficient. Earlier today, I posted an article about the CSV parser that I wrote almost a year ago, which handles badly formed CSV strings by way of a simple, but effective state machine, which is similar to your recursive descent parser, but without the burden and potential risk associated with a recursive algorithm.
IMO, while there are circumstances in which a recursive algorithm truly is the best solution, in many cases, there is a non-recursive algorithm that achieves the same result more safely.
|
|
|
|
|
function [bestParameter1,bestParameter2] = ransac_demo(data,num,iter,threshDist,inlierRatio)
% data: a 2xn dataset with #n data points
% num: the minimum number of points. For line fitting problem, num=2
% iter: the number of iterations
% threshDist: the threshold of the distances between points and the fitting line
% inlierRatio: the threshold of the numer of inliers
%% Plot the data points
figure;plot(data(1, ,data(2, ,'o');hold on;
number = size(data,2); % Total number of points
bestInNum = 0; % Best fitting line with largest number of inliers
bestParameter1=0;bestParameter2=0; % parameters for best fitting line
for i=1:iter
%% Randomly select 2 points
idx = randperm(number,num); sample = data(:,idx);
%% Compute the distances between all points with the fitting line
kLine = sample(:,2)-sample(:,1);
kLineNorm = kLine/norm(kLine);
normVector = [-kLineNorm(2),kLineNorm(1)];
distance = normVector*(data - repmat(sample(:,1),1,number));
%% Compute the inliers with distances smaller than the threshold
inlierIdx = find(abs(distance)<=threshDist);
inlierNum = length(inlierIdx);
%% Update the number of inliers and fitting model if better model is found
if inlierNum>=round(inlierRatio*number) && inlierNum>bestInNum
bestInNum = inlierNum;
parameter1 = (sample(2,2)-sample(2,1))/(sample(1,2)-sample(1,1));
parameter2 = sample(2,1)-parameter1*sample(1,1);
bestParameter1=parameter1; bestParameter2=parameter2;
end
end
%% Plot the best fitting line
xAxis = -number/2:number/2;
yAxis = bestParameter1*xAxis + bestParameter2;
plot(xAxis,yAxis,'r-','LineWidth',2);
|
|
|
|
|
What have you tried?
What problems have you met?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
With which line do you need help?
I doubt that anyone is going to convert the complete procedure, just for the fun of it
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
I had to implement that once (in Delphi), but I would not have recognized it by reading matlab-code*
*) nor out of the comments in the header.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi !
if the input data is a list of points how can i select randomly just 2 points from it ?
how to convert this line :
%% Randomly select 2 points
idx = randperm(number,num); sample = data(:,idx);
int number = data.Count; // Total number of points
int bestInNum = 0; //Best fitting line with largest number of inliers
int bestParameter1=0 ,bestParameter2=0; //parameters for best fitting line
for (int i = 1; i < iter; i++)
{
//Randomly select 2 points
Random rnd = new Random();
//....??
}
|
|
|
|
|
int idx = rnd.Next(0, myList.Length); That is assuming a Generic List, and only returns a single, random index. Described here[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
thanks
but if i try like this ,is it possible?
IList<point>[] data;
IList<point> model;
int number = data.Length;
//Randomly select 2 points
Random rnd = new Random();
int idx = rnd.Next(2, number);model=data[idx];
|
|
|
|
|
int idx = rnd.Next(2, number); That would give you a random number between 2 and number , not two numbers. If you want another random number after the first, you'd have to ask for the "Next" number again (between min, max).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You should give it a try yourself and come back when you have trouble at a specific point. The code looks pretty much straight forward to translate with the help from google.
|
|
|
|
|
Hi,
I have problem in this code
string w;
private void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string[] data_from_computer;
data_from_computer = new string[3];
int x ;
w = Port.ReadTo("ST").ToString();
if (w != string.Empty)
{
data_from_computer[0] = ""+w[0];
data_from_computer[1] = ""+w[1];
label2.Text = data_from_computer[1];
}
where must be send data twice for least to response the code
I mean for example I need send this data "STA"
the code
w = Port.ReadTo("ST").ToString();
is read ST and store A in W
But if send data first time for example "STA" the program or code not work
then must be data "STA""STA" then the code is work why??
note Port is name for serialport
Regards
|
|
|
|
|
Hi,
How can to locomp instrumentation because i need add this tools to toolbox for visual studio 2012
I mean I need Link for download it
Regards
|
|
|
|
|
Try their website[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You could go to theier site: http://www.iocomp.com/Downloads/Default.aspx[^] and download it from there.
Of course you will probably have to pay for it, but you knew that, didn't you?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
cant buy because is expensive and need some tools only for example seven segment , gauge , led , switch ,
Regards
|
|
|
|
|
Then you will not find a link here.
We do not condone, support or assist in copyright violation in any way, form or manner. This is a professional site for professional developers.
And asking for such again will get you banned from the site very, very quickly.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|