Shahgee
Shahgee

Reputation: 3405

Data reading and storing in c#, (Concept..no code)

I want to translate my Matlab code (least squares plane fitting) into C#. I have many problems in understanding c#. Let me ask here. Reading a text file and storing data in xyz format in matrix (e.g., xyzdata= xyz) in Matlab is quite easy. Translating it into CSharp? How can I read [x y z] without knowing length of file and how can I store it in Matrix form? Thank you very much for your help and If someone has plane fitting code / link, please guide me.

Upvotes: 0

Views: 206

Answers (1)

Gert Arnold
Gert Arnold

Reputation: 109079

I don't know the content of your text file, but File.ReadAllLines is the easiest way to read a text file into a string array representing all lines in the file. No trouble with having to know the length of the file.

If the lines contain the entries of your matrix, the next step would be looping through the lines and for each line use String.Split to get the individual elements.

When you've got that far, you have all information for creating a matrix of the required size. To fill its elements you're going to need Int32.Parse or Decimal.Parse to convert the elements as string into numbers.

However, hard to tell from your post what kind of matrix you'll need (probably a multi dimensional array). Search "[matrix] [c#]" here at stack overflow. And try "[math] [.net]" to find posts on math libraries for .net.

Upvotes: 1

Related Questions