matrix in visual basicWriting a matrix to a text fileAn optimal way of finding the first row with only '0' elements in matrix?Matrix input result (Python)Impossible to remove rows from matrix with Math.NET NumericsIn-Place CUDA Kernel for Rectangular Matrix TransposeConstrained maximization of the sum of square submatricescreate a 24*30 matrix from a 100*30 matrix excel vbaSuppose we have a matrix, 100 rows and 100 columns, of 2-byte integersMatrix class C++Java OOP Changing the position of 2d matrix?How to scan integers into a square matrix (2D array)? (Matrix size unknown before compilation)

Car headlights in a world without electricity

How can a day be of 24 hours?

Am I breaking OOP practice with this architecture?

What do you call someone who asks many questions?

Finitely generated matrix groups whose eigenvalues are all algebraic

Does Dispel Magic work on Tiny Hut?

Is there an online compendium of Rav Moshe teshuvos in English that exists?

Why were 5.25" floppy drives cheaper than 8"?

How to show a landlord what we have in savings?

One verb to replace 'be a member of' a club

What is a Samsaran Word™?

Do creatures with a listed speed of "0 ft., fly 30 ft. (hover)" ever touch the ground?

how do we prove that a sum of two periods is still a period?

Why didn't Boeing produce its own regional jet?

What is the opposite of "eschatology"?

Venezuelan girlfriend wants to travel the USA to be with me. What is the process?

In Bayesian inference, why are some terms dropped from the posterior predictive?

How to install cross-compiler on Ubuntu 18.04?

Do Iron Man suits sport waste management systems?

Should I tell management that I intend to leave due to bad software development practices?

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

What is the fastest integer factorization to break RSA?

How obscure is the use of 令 in 令和?

files created then deleted at every second in tmp directory



matrix in visual basic


Writing a matrix to a text fileAn optimal way of finding the first row with only '0' elements in matrix?Matrix input result (Python)Impossible to remove rows from matrix with Math.NET NumericsIn-Place CUDA Kernel for Rectangular Matrix TransposeConstrained maximization of the sum of square submatricescreate a 24*30 matrix from a 100*30 matrix excel vbaSuppose we have a matrix, 100 rows and 100 columns, of 2-byte integersMatrix class C++Java OOP Changing the position of 2d matrix?How to scan integers into a square matrix (2D array)? (Matrix size unknown before compilation)













0















so i have a task to create a square matrix then from that return the average of the rows and columns, having some problem though



Dim m, n, i, j As Integer
Dim A(2, 2) As Integer
Console.Write(vbLf & "Enter The Matrix Elements any two : ")
For i = 0 To 2 - 1
For j = 0 To 2 = 1
A(i, j) = Convert.ToInt16(Console.ReadLine())
Next
Next
Console.Clear()
Console.WriteLine(vbLf & "Matrix A : ")
For i = 0 To 2 - 1
For j = 0 To 2 - 1
Console.Write(vbLf & "0", A(i, j))
Next

Console.WriteLine(" ")
Next


Console.WriteLine(vbLf & "Transpose Matrix : ")

For i = 0 To 2 - 1
For j = 0 To 2 - 1
Console.Write(vbLf & "0", A(j, i))

Next

Console.WriteLine(" ")
Next
End Sub


This is my code, i know its supposed to be a square matrix so how would i do that, when i also try inputing the values it does not let me go past the next one, does anyone have code for a square matrix that gets its values from a user, or someone can help me please










share|improve this question

















  • 1





    Is For j = 0 To 2 = 1 a typo?

    – Honeyboy Wilson
    Mar 21 at 20:45











  • How big do you want this matrix? In vb, the subscript is the index of the last item, so Dim A(2,2) As Integer is actually a 3x3 array.

    – Joel Coehoorn
    Mar 21 at 20:48











  • Also, I see this: For j = 0 To 2 = 1, which might just be a typo moving code to Stack Overflow, but is certainly not what you intend with the second = sign.

    – Joel Coehoorn
    Mar 21 at 20:50











  • @JoelCoehoorn i gave this code to someone and they edited that in, i don't know why, basically this is what i want, if say its a 2x2 matix, user is requested to enter, the values for the 4 values in the array, then the array is displayed, the values being (a, b) (c, d) - from this i can do the averages and other things, but its supposed to be a 2d array so really confused, appreciate ur help aswell

    – loco3424
    Mar 21 at 21:12
















0















so i have a task to create a square matrix then from that return the average of the rows and columns, having some problem though



Dim m, n, i, j As Integer
Dim A(2, 2) As Integer
Console.Write(vbLf & "Enter The Matrix Elements any two : ")
For i = 0 To 2 - 1
For j = 0 To 2 = 1
A(i, j) = Convert.ToInt16(Console.ReadLine())
Next
Next
Console.Clear()
Console.WriteLine(vbLf & "Matrix A : ")
For i = 0 To 2 - 1
For j = 0 To 2 - 1
Console.Write(vbLf & "0", A(i, j))
Next

Console.WriteLine(" ")
Next


Console.WriteLine(vbLf & "Transpose Matrix : ")

For i = 0 To 2 - 1
For j = 0 To 2 - 1
Console.Write(vbLf & "0", A(j, i))

Next

Console.WriteLine(" ")
Next
End Sub


This is my code, i know its supposed to be a square matrix so how would i do that, when i also try inputing the values it does not let me go past the next one, does anyone have code for a square matrix that gets its values from a user, or someone can help me please










share|improve this question

















  • 1





    Is For j = 0 To 2 = 1 a typo?

    – Honeyboy Wilson
    Mar 21 at 20:45











  • How big do you want this matrix? In vb, the subscript is the index of the last item, so Dim A(2,2) As Integer is actually a 3x3 array.

    – Joel Coehoorn
    Mar 21 at 20:48











  • Also, I see this: For j = 0 To 2 = 1, which might just be a typo moving code to Stack Overflow, but is certainly not what you intend with the second = sign.

    – Joel Coehoorn
    Mar 21 at 20:50











  • @JoelCoehoorn i gave this code to someone and they edited that in, i don't know why, basically this is what i want, if say its a 2x2 matix, user is requested to enter, the values for the 4 values in the array, then the array is displayed, the values being (a, b) (c, d) - from this i can do the averages and other things, but its supposed to be a 2d array so really confused, appreciate ur help aswell

    – loco3424
    Mar 21 at 21:12














0












0








0








so i have a task to create a square matrix then from that return the average of the rows and columns, having some problem though



Dim m, n, i, j As Integer
Dim A(2, 2) As Integer
Console.Write(vbLf & "Enter The Matrix Elements any two : ")
For i = 0 To 2 - 1
For j = 0 To 2 = 1
A(i, j) = Convert.ToInt16(Console.ReadLine())
Next
Next
Console.Clear()
Console.WriteLine(vbLf & "Matrix A : ")
For i = 0 To 2 - 1
For j = 0 To 2 - 1
Console.Write(vbLf & "0", A(i, j))
Next

Console.WriteLine(" ")
Next


Console.WriteLine(vbLf & "Transpose Matrix : ")

For i = 0 To 2 - 1
For j = 0 To 2 - 1
Console.Write(vbLf & "0", A(j, i))

Next

Console.WriteLine(" ")
Next
End Sub


This is my code, i know its supposed to be a square matrix so how would i do that, when i also try inputing the values it does not let me go past the next one, does anyone have code for a square matrix that gets its values from a user, or someone can help me please










share|improve this question














so i have a task to create a square matrix then from that return the average of the rows and columns, having some problem though



Dim m, n, i, j As Integer
Dim A(2, 2) As Integer
Console.Write(vbLf & "Enter The Matrix Elements any two : ")
For i = 0 To 2 - 1
For j = 0 To 2 = 1
A(i, j) = Convert.ToInt16(Console.ReadLine())
Next
Next
Console.Clear()
Console.WriteLine(vbLf & "Matrix A : ")
For i = 0 To 2 - 1
For j = 0 To 2 - 1
Console.Write(vbLf & "0", A(i, j))
Next

Console.WriteLine(" ")
Next


Console.WriteLine(vbLf & "Transpose Matrix : ")

For i = 0 To 2 - 1
For j = 0 To 2 - 1
Console.Write(vbLf & "0", A(j, i))

Next

Console.WriteLine(" ")
Next
End Sub


This is my code, i know its supposed to be a square matrix so how would i do that, when i also try inputing the values it does not let me go past the next one, does anyone have code for a square matrix that gets its values from a user, or someone can help me please







arrays vb.net matrix






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 21 at 20:40









loco3424loco3424

64




64







  • 1





    Is For j = 0 To 2 = 1 a typo?

    – Honeyboy Wilson
    Mar 21 at 20:45











  • How big do you want this matrix? In vb, the subscript is the index of the last item, so Dim A(2,2) As Integer is actually a 3x3 array.

    – Joel Coehoorn
    Mar 21 at 20:48











  • Also, I see this: For j = 0 To 2 = 1, which might just be a typo moving code to Stack Overflow, but is certainly not what you intend with the second = sign.

    – Joel Coehoorn
    Mar 21 at 20:50











  • @JoelCoehoorn i gave this code to someone and they edited that in, i don't know why, basically this is what i want, if say its a 2x2 matix, user is requested to enter, the values for the 4 values in the array, then the array is displayed, the values being (a, b) (c, d) - from this i can do the averages and other things, but its supposed to be a 2d array so really confused, appreciate ur help aswell

    – loco3424
    Mar 21 at 21:12













  • 1





    Is For j = 0 To 2 = 1 a typo?

    – Honeyboy Wilson
    Mar 21 at 20:45











  • How big do you want this matrix? In vb, the subscript is the index of the last item, so Dim A(2,2) As Integer is actually a 3x3 array.

    – Joel Coehoorn
    Mar 21 at 20:48











  • Also, I see this: For j = 0 To 2 = 1, which might just be a typo moving code to Stack Overflow, but is certainly not what you intend with the second = sign.

    – Joel Coehoorn
    Mar 21 at 20:50











  • @JoelCoehoorn i gave this code to someone and they edited that in, i don't know why, basically this is what i want, if say its a 2x2 matix, user is requested to enter, the values for the 4 values in the array, then the array is displayed, the values being (a, b) (c, d) - from this i can do the averages and other things, but its supposed to be a 2d array so really confused, appreciate ur help aswell

    – loco3424
    Mar 21 at 21:12








1




1





Is For j = 0 To 2 = 1 a typo?

– Honeyboy Wilson
Mar 21 at 20:45





Is For j = 0 To 2 = 1 a typo?

– Honeyboy Wilson
Mar 21 at 20:45













How big do you want this matrix? In vb, the subscript is the index of the last item, so Dim A(2,2) As Integer is actually a 3x3 array.

– Joel Coehoorn
Mar 21 at 20:48





How big do you want this matrix? In vb, the subscript is the index of the last item, so Dim A(2,2) As Integer is actually a 3x3 array.

– Joel Coehoorn
Mar 21 at 20:48













Also, I see this: For j = 0 To 2 = 1, which might just be a typo moving code to Stack Overflow, but is certainly not what you intend with the second = sign.

– Joel Coehoorn
Mar 21 at 20:50





Also, I see this: For j = 0 To 2 = 1, which might just be a typo moving code to Stack Overflow, but is certainly not what you intend with the second = sign.

– Joel Coehoorn
Mar 21 at 20:50













@JoelCoehoorn i gave this code to someone and they edited that in, i don't know why, basically this is what i want, if say its a 2x2 matix, user is requested to enter, the values for the 4 values in the array, then the array is displayed, the values being (a, b) (c, d) - from this i can do the averages and other things, but its supposed to be a 2d array so really confused, appreciate ur help aswell

– loco3424
Mar 21 at 21:12






@JoelCoehoorn i gave this code to someone and they edited that in, i don't know why, basically this is what i want, if say its a 2x2 matix, user is requested to enter, the values for the 4 values in the array, then the array is displayed, the values being (a, b) (c, d) - from this i can do the averages and other things, but its supposed to be a 2d array so really confused, appreciate ur help aswell

– loco3424
Mar 21 at 21:12













1 Answer
1






active

oldest

votes


















1














To make it generic, use the GetUpperBound() function to determine how many elements are in your array for each dimension (it should be the same, however, since you have a square matrix):



Sub Main()
Dim size As Integer = 3
Dim numberWidth As Integer = 2
Dim format As String = "D" & numberWidth

Dim A(size - 1, size - 1) As Integer
For i As Integer = 0 To A.GetUpperBound(0)
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write(String.Format("Enter The Matrix Element at A[Row 0, Col 1]: ", i, j))
A(i, j) = Convert.ToInt16(Console.ReadLine())
Next
Next

Console.WriteLine("Matrix A :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(i, j).ToString(format))
Next
Console.WriteLine("|")
Next

Console.WriteLine("Transpose Matrix :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(j, i).ToString(format))
Next
Console.WriteLine("|")
Next
Console.ReadLine()
End Sub


Output:



Enter The Matrix Element at A[Row 0, Col 0]: 1
Enter The Matrix Element at A[Row 0, Col 1]: 2
Enter The Matrix Element at A[Row 0, Col 2]: 3
Enter The Matrix Element at A[Row 1, Col 0]: 4
Enter The Matrix Element at A[Row 1, Col 1]: 5
Enter The Matrix Element at A[Row 1, Col 2]: 6
Enter The Matrix Element at A[Row 2, Col 0]: 7
Enter The Matrix Element at A[Row 2, Col 1]: 8
Enter The Matrix Element at A[Row 2, Col 2]: 9
Matrix A :
| 01 02 03 |
| 04 05 06 |
| 07 08 09 |
Transpose Matrix :
| 01 04 07 |
| 02 05 08 |
| 03 06 09 |


Here's a quick example of how to compute the SUM of each ROW:



Dim Total as Integer
For row As Integer = 0 To A.GetUpperBound(0)
Total = 0 ' reset for each row/column
For col As Integer = 0 To A.GetUpperBound(1)
Total = Total + A(row, col)
Next
Console.WriteLine("Row " & row & " total: " & Total)
' ... do something else with "Total" here; like compute an average ...
Next


The code for computing the total of columns will be very similar, just swap the positions of the For row and For col lines.






share|improve this answer

























  • thats cool bro yeah learnt about upper and lower bound in my last post, thanks for explaining, however how would i use this to be able to calculate the rows and column sum,

    – loco3424
    Mar 21 at 21:30












  • You can use the same nested for loop structure already being demonstrated for the output, to compute the sum of each row. You'd switch the order of the rows/cols for loops to get the column sums. I'll post something in a bit, have to hit the road.

    – Idle_Mind
    Mar 21 at 21:52











  • Cool, thanks, much appericated, have good one on the roads

    – loco3424
    Mar 21 at 22:04











  • yes i would have to calculate the averages and wanted to try this, however one problem, when i tried to enter this code just to see if it works, it would not work just got a error

    – loco3424
    Mar 22 at 15:55






  • 1





    smashed it mate, did the averages today and the column count today, thanks for explaining also bro

    – loco3424
    Mar 23 at 15:57











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288915%2fmatrix-in-visual-basic%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














To make it generic, use the GetUpperBound() function to determine how many elements are in your array for each dimension (it should be the same, however, since you have a square matrix):



Sub Main()
Dim size As Integer = 3
Dim numberWidth As Integer = 2
Dim format As String = "D" & numberWidth

Dim A(size - 1, size - 1) As Integer
For i As Integer = 0 To A.GetUpperBound(0)
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write(String.Format("Enter The Matrix Element at A[Row 0, Col 1]: ", i, j))
A(i, j) = Convert.ToInt16(Console.ReadLine())
Next
Next

Console.WriteLine("Matrix A :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(i, j).ToString(format))
Next
Console.WriteLine("|")
Next

Console.WriteLine("Transpose Matrix :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(j, i).ToString(format))
Next
Console.WriteLine("|")
Next
Console.ReadLine()
End Sub


Output:



Enter The Matrix Element at A[Row 0, Col 0]: 1
Enter The Matrix Element at A[Row 0, Col 1]: 2
Enter The Matrix Element at A[Row 0, Col 2]: 3
Enter The Matrix Element at A[Row 1, Col 0]: 4
Enter The Matrix Element at A[Row 1, Col 1]: 5
Enter The Matrix Element at A[Row 1, Col 2]: 6
Enter The Matrix Element at A[Row 2, Col 0]: 7
Enter The Matrix Element at A[Row 2, Col 1]: 8
Enter The Matrix Element at A[Row 2, Col 2]: 9
Matrix A :
| 01 02 03 |
| 04 05 06 |
| 07 08 09 |
Transpose Matrix :
| 01 04 07 |
| 02 05 08 |
| 03 06 09 |


Here's a quick example of how to compute the SUM of each ROW:



Dim Total as Integer
For row As Integer = 0 To A.GetUpperBound(0)
Total = 0 ' reset for each row/column
For col As Integer = 0 To A.GetUpperBound(1)
Total = Total + A(row, col)
Next
Console.WriteLine("Row " & row & " total: " & Total)
' ... do something else with "Total" here; like compute an average ...
Next


The code for computing the total of columns will be very similar, just swap the positions of the For row and For col lines.






share|improve this answer

























  • thats cool bro yeah learnt about upper and lower bound in my last post, thanks for explaining, however how would i use this to be able to calculate the rows and column sum,

    – loco3424
    Mar 21 at 21:30












  • You can use the same nested for loop structure already being demonstrated for the output, to compute the sum of each row. You'd switch the order of the rows/cols for loops to get the column sums. I'll post something in a bit, have to hit the road.

    – Idle_Mind
    Mar 21 at 21:52











  • Cool, thanks, much appericated, have good one on the roads

    – loco3424
    Mar 21 at 22:04











  • yes i would have to calculate the averages and wanted to try this, however one problem, when i tried to enter this code just to see if it works, it would not work just got a error

    – loco3424
    Mar 22 at 15:55






  • 1





    smashed it mate, did the averages today and the column count today, thanks for explaining also bro

    – loco3424
    Mar 23 at 15:57















1














To make it generic, use the GetUpperBound() function to determine how many elements are in your array for each dimension (it should be the same, however, since you have a square matrix):



Sub Main()
Dim size As Integer = 3
Dim numberWidth As Integer = 2
Dim format As String = "D" & numberWidth

Dim A(size - 1, size - 1) As Integer
For i As Integer = 0 To A.GetUpperBound(0)
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write(String.Format("Enter The Matrix Element at A[Row 0, Col 1]: ", i, j))
A(i, j) = Convert.ToInt16(Console.ReadLine())
Next
Next

Console.WriteLine("Matrix A :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(i, j).ToString(format))
Next
Console.WriteLine("|")
Next

Console.WriteLine("Transpose Matrix :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(j, i).ToString(format))
Next
Console.WriteLine("|")
Next
Console.ReadLine()
End Sub


Output:



Enter The Matrix Element at A[Row 0, Col 0]: 1
Enter The Matrix Element at A[Row 0, Col 1]: 2
Enter The Matrix Element at A[Row 0, Col 2]: 3
Enter The Matrix Element at A[Row 1, Col 0]: 4
Enter The Matrix Element at A[Row 1, Col 1]: 5
Enter The Matrix Element at A[Row 1, Col 2]: 6
Enter The Matrix Element at A[Row 2, Col 0]: 7
Enter The Matrix Element at A[Row 2, Col 1]: 8
Enter The Matrix Element at A[Row 2, Col 2]: 9
Matrix A :
| 01 02 03 |
| 04 05 06 |
| 07 08 09 |
Transpose Matrix :
| 01 04 07 |
| 02 05 08 |
| 03 06 09 |


Here's a quick example of how to compute the SUM of each ROW:



Dim Total as Integer
For row As Integer = 0 To A.GetUpperBound(0)
Total = 0 ' reset for each row/column
For col As Integer = 0 To A.GetUpperBound(1)
Total = Total + A(row, col)
Next
Console.WriteLine("Row " & row & " total: " & Total)
' ... do something else with "Total" here; like compute an average ...
Next


The code for computing the total of columns will be very similar, just swap the positions of the For row and For col lines.






share|improve this answer

























  • thats cool bro yeah learnt about upper and lower bound in my last post, thanks for explaining, however how would i use this to be able to calculate the rows and column sum,

    – loco3424
    Mar 21 at 21:30












  • You can use the same nested for loop structure already being demonstrated for the output, to compute the sum of each row. You'd switch the order of the rows/cols for loops to get the column sums. I'll post something in a bit, have to hit the road.

    – Idle_Mind
    Mar 21 at 21:52











  • Cool, thanks, much appericated, have good one on the roads

    – loco3424
    Mar 21 at 22:04











  • yes i would have to calculate the averages and wanted to try this, however one problem, when i tried to enter this code just to see if it works, it would not work just got a error

    – loco3424
    Mar 22 at 15:55






  • 1





    smashed it mate, did the averages today and the column count today, thanks for explaining also bro

    – loco3424
    Mar 23 at 15:57













1












1








1







To make it generic, use the GetUpperBound() function to determine how many elements are in your array for each dimension (it should be the same, however, since you have a square matrix):



Sub Main()
Dim size As Integer = 3
Dim numberWidth As Integer = 2
Dim format As String = "D" & numberWidth

Dim A(size - 1, size - 1) As Integer
For i As Integer = 0 To A.GetUpperBound(0)
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write(String.Format("Enter The Matrix Element at A[Row 0, Col 1]: ", i, j))
A(i, j) = Convert.ToInt16(Console.ReadLine())
Next
Next

Console.WriteLine("Matrix A :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(i, j).ToString(format))
Next
Console.WriteLine("|")
Next

Console.WriteLine("Transpose Matrix :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(j, i).ToString(format))
Next
Console.WriteLine("|")
Next
Console.ReadLine()
End Sub


Output:



Enter The Matrix Element at A[Row 0, Col 0]: 1
Enter The Matrix Element at A[Row 0, Col 1]: 2
Enter The Matrix Element at A[Row 0, Col 2]: 3
Enter The Matrix Element at A[Row 1, Col 0]: 4
Enter The Matrix Element at A[Row 1, Col 1]: 5
Enter The Matrix Element at A[Row 1, Col 2]: 6
Enter The Matrix Element at A[Row 2, Col 0]: 7
Enter The Matrix Element at A[Row 2, Col 1]: 8
Enter The Matrix Element at A[Row 2, Col 2]: 9
Matrix A :
| 01 02 03 |
| 04 05 06 |
| 07 08 09 |
Transpose Matrix :
| 01 04 07 |
| 02 05 08 |
| 03 06 09 |


Here's a quick example of how to compute the SUM of each ROW:



Dim Total as Integer
For row As Integer = 0 To A.GetUpperBound(0)
Total = 0 ' reset for each row/column
For col As Integer = 0 To A.GetUpperBound(1)
Total = Total + A(row, col)
Next
Console.WriteLine("Row " & row & " total: " & Total)
' ... do something else with "Total" here; like compute an average ...
Next


The code for computing the total of columns will be very similar, just swap the positions of the For row and For col lines.






share|improve this answer















To make it generic, use the GetUpperBound() function to determine how many elements are in your array for each dimension (it should be the same, however, since you have a square matrix):



Sub Main()
Dim size As Integer = 3
Dim numberWidth As Integer = 2
Dim format As String = "D" & numberWidth

Dim A(size - 1, size - 1) As Integer
For i As Integer = 0 To A.GetUpperBound(0)
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write(String.Format("Enter The Matrix Element at A[Row 0, Col 1]: ", i, j))
A(i, j) = Convert.ToInt16(Console.ReadLine())
Next
Next

Console.WriteLine("Matrix A :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(i, j).ToString(format))
Next
Console.WriteLine("|")
Next

Console.WriteLine("Transpose Matrix :")
For i As Integer = 0 To A.GetUpperBound(0)
Console.Write("| ")
For j As Integer = 0 To A.GetUpperBound(1)
Console.Write("0 ", A(j, i).ToString(format))
Next
Console.WriteLine("|")
Next
Console.ReadLine()
End Sub


Output:



Enter The Matrix Element at A[Row 0, Col 0]: 1
Enter The Matrix Element at A[Row 0, Col 1]: 2
Enter The Matrix Element at A[Row 0, Col 2]: 3
Enter The Matrix Element at A[Row 1, Col 0]: 4
Enter The Matrix Element at A[Row 1, Col 1]: 5
Enter The Matrix Element at A[Row 1, Col 2]: 6
Enter The Matrix Element at A[Row 2, Col 0]: 7
Enter The Matrix Element at A[Row 2, Col 1]: 8
Enter The Matrix Element at A[Row 2, Col 2]: 9
Matrix A :
| 01 02 03 |
| 04 05 06 |
| 07 08 09 |
Transpose Matrix :
| 01 04 07 |
| 02 05 08 |
| 03 06 09 |


Here's a quick example of how to compute the SUM of each ROW:



Dim Total as Integer
For row As Integer = 0 To A.GetUpperBound(0)
Total = 0 ' reset for each row/column
For col As Integer = 0 To A.GetUpperBound(1)
Total = Total + A(row, col)
Next
Console.WriteLine("Row " & row & " total: " & Total)
' ... do something else with "Total" here; like compute an average ...
Next


The code for computing the total of columns will be very similar, just swap the positions of the For row and For col lines.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 at 21:26

























answered Mar 21 at 21:24









Idle_MindIdle_Mind

24k21524




24k21524












  • thats cool bro yeah learnt about upper and lower bound in my last post, thanks for explaining, however how would i use this to be able to calculate the rows and column sum,

    – loco3424
    Mar 21 at 21:30












  • You can use the same nested for loop structure already being demonstrated for the output, to compute the sum of each row. You'd switch the order of the rows/cols for loops to get the column sums. I'll post something in a bit, have to hit the road.

    – Idle_Mind
    Mar 21 at 21:52











  • Cool, thanks, much appericated, have good one on the roads

    – loco3424
    Mar 21 at 22:04











  • yes i would have to calculate the averages and wanted to try this, however one problem, when i tried to enter this code just to see if it works, it would not work just got a error

    – loco3424
    Mar 22 at 15:55






  • 1





    smashed it mate, did the averages today and the column count today, thanks for explaining also bro

    – loco3424
    Mar 23 at 15:57

















  • thats cool bro yeah learnt about upper and lower bound in my last post, thanks for explaining, however how would i use this to be able to calculate the rows and column sum,

    – loco3424
    Mar 21 at 21:30












  • You can use the same nested for loop structure already being demonstrated for the output, to compute the sum of each row. You'd switch the order of the rows/cols for loops to get the column sums. I'll post something in a bit, have to hit the road.

    – Idle_Mind
    Mar 21 at 21:52











  • Cool, thanks, much appericated, have good one on the roads

    – loco3424
    Mar 21 at 22:04











  • yes i would have to calculate the averages and wanted to try this, however one problem, when i tried to enter this code just to see if it works, it would not work just got a error

    – loco3424
    Mar 22 at 15:55






  • 1





    smashed it mate, did the averages today and the column count today, thanks for explaining also bro

    – loco3424
    Mar 23 at 15:57
















thats cool bro yeah learnt about upper and lower bound in my last post, thanks for explaining, however how would i use this to be able to calculate the rows and column sum,

– loco3424
Mar 21 at 21:30






thats cool bro yeah learnt about upper and lower bound in my last post, thanks for explaining, however how would i use this to be able to calculate the rows and column sum,

– loco3424
Mar 21 at 21:30














You can use the same nested for loop structure already being demonstrated for the output, to compute the sum of each row. You'd switch the order of the rows/cols for loops to get the column sums. I'll post something in a bit, have to hit the road.

– Idle_Mind
Mar 21 at 21:52





You can use the same nested for loop structure already being demonstrated for the output, to compute the sum of each row. You'd switch the order of the rows/cols for loops to get the column sums. I'll post something in a bit, have to hit the road.

– Idle_Mind
Mar 21 at 21:52













Cool, thanks, much appericated, have good one on the roads

– loco3424
Mar 21 at 22:04





Cool, thanks, much appericated, have good one on the roads

– loco3424
Mar 21 at 22:04













yes i would have to calculate the averages and wanted to try this, however one problem, when i tried to enter this code just to see if it works, it would not work just got a error

– loco3424
Mar 22 at 15:55





yes i would have to calculate the averages and wanted to try this, however one problem, when i tried to enter this code just to see if it works, it would not work just got a error

– loco3424
Mar 22 at 15:55




1




1





smashed it mate, did the averages today and the column count today, thanks for explaining also bro

– loco3424
Mar 23 at 15:57





smashed it mate, did the averages today and the column count today, thanks for explaining also bro

– loco3424
Mar 23 at 15:57



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288915%2fmatrix-in-visual-basic%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현