Two dimensional matrix in Perl [closed] - perl

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Newbie's question: What does $matrix[$row][4]=1; mean in a code? The row and column are known to me. Why is it made equal to 1?

The command will set the cell at position $row,4 with the value 1

= is the assignment operator in Perl. It assigns the value 1 to the cell at the coordinates $row, 4.
The comparison operators for equiality are eq for strings and == for numbers.

Related

Matlab : Opposite function of "primes" in matlab [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Is there any opposite function of "primes" in matlab?
(Primes : Prime numbers less than or equal to input value)
What if i want to find greater than or equal to input value?
Thank you.
You always have to provide an upper limit. If you wanted prime numbers "greater than or equal to the given value," they would go to infinity.
I would suggest starting with "less than or equal to," provide the function with an upper limit, and then use a conditional to filter out those that are too small.

How to compare two matrices on MatLab? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Given a matrix A and a matrix B, how do I compare them element by element so the program returns a third matrix C that shows:
- If the element in A is larger than the one in B, the element in C should be 1.
- If the element in A is smaller than in B, the element in C should be -1.
- If the elements of both matrices are equal, the element in C should be 0.
Hope you can help!
C=zeros(size(A));
C(A>B) = 1;
C(A<B) = -1;
Note that it's never a good idea to do an equality test on floating point numbers.

Returning the last element of a vector with an unknown length [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can I retrieve the last element of a vector only, provided that the length of that vector is unknown?
Use the special end keyword:
lastelement = myvector(end);
If the vector is called A, just use A(end).
In this case, use end, like #nispio and #David answered.
But it seems you think that not knowing the length can be a problem, but nope. That's because you can use length(v) if v is a column or row vector, or size(M) if M is a matrix.
Then, to get the last element of your vector, you could use (not recommended):
v(length(v)) if v is a row or a column vector
v(size(v,1)) if v is a column vector
v(size(v,2)) if v is a row vector
But if you use one of them, MATLAB will warn you:
The operation or expression <Indexing> has no evident effect.

getting occurrence of alphabets in a string, in Matlab [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i have to do huffman coding on a message read from a file,in Matlab.For that i have to find the probability occurrence of each alphabet in that message.Using that frequency i have to do huffman encoding.Can you please specify how to read a message from the file and store it as a string for the same purpose..Can anyone help me to solve this
What you need is a histogram count:
counts = histc(lower(x), 'a':'z');
where the output count contains the number of occurences for each letter in the message string x. For instance, the first element count(1) corresponds to the number of occurrences of a, count(2) corresponds to the number of occurrences of b, etc...
Also note that this x is converted to lowercase o make the counting case insensitive.

Basic Matlab tables containing text [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I need to type some matrix containing both letters and numbers.
Something like list=["a" 1;" b" 2; "c" 3; "d" 4; "e" 5; "f" 6; "g" 7]
Can anybody give me some tip?
If you want "just" a mix of strings and numbers, use a cell array. See the MATLAB documentation here.
If you're trying to set up some kind of map/hash, you want a MATLAB "structure." See the documentation for that here.