What is meaning of c(:,1) and . in matlab code

I have code .What does it mean?
c(:,1)=0.5*ones(10,1); //What is c(:, 1)?
for i = 1:s
Delta(:,i)=(2*round(rand(2,1))-1).*rand(2,1); //What is .?
end
for m=1:s
P(1,:,1,1,1)= 50*rand(s,1)'; //What is ' and P(1, :, 1,1,1)?
P(2,:,1,1,1)= 0.2*rand(s,1)';
end

 Réponse acceptée

Jan
Jan le 26 Avr 2016

6 votes

I agree with dpb: To use a powerful programming language like Matlab, you have to read the manuals. The forum is not the right location to explain the basics, because they are explained in the "Getting Started" chapters exhaustively already.
  • You will find out, that c(:,1) is the first column of the matrix "c", e.g. a column vector.
  • The operator is not "." but ".*", which means an elementwise multiplication. A * B is a matrix product, while A .* B multiplies the elements of the arrays.

4 commentaires

LOKESH
LOKESH le 27 Avr 2016
Modifié(e) : LOKESH le 27 Avr 2016
Thanks your answer helped me lot.
I am unable to get the meaning of:
for m=1:s
P(1,:,1,1,1)= 50*rand(s,1)'; //P(1, :, 1,1,1)?
P(2,:,1,1,1)= 0.2*rand(s,1)';
end
P(1, :,1,1,1) is equivalent to X = ones(sz1,...,szN,classname) returns an sz1-by-...-by-szN array of ones of data type classname.
You see why reading the "Getting Started" chapters is something you cannot avoid? It would not be efficient if we tell you what is written there in a compact and clear way.
  • ' is the transpose operator.
  • P(1, :, 1, 1, 1) is the vector along the 2nd dimension of the 5D-array P. Example in 2D:
X = rand(2, 3)
X(:, 1);
X(2, :)
And now rely on reading the documentation instead of waiting for the forum to rephrase it with hours of time delay.
Jan
Jan le 6 Juin 2022
[MOVED from flags] Paula Carrasco Molina about 2 hours ago. Hey man, sometimes you're not using Matlab every day and only want to solve a straightforward question and forget Matlab forever. If you're going to answer like that, better not respond and let someone else do it
Jan
Jan le 6 Juin 2022
Modifié(e) : Jan le 6 Juin 2022
@Paula Carrasco Molina: I've explained, what these operators do and in addition how you can find this out by your own. If you have a good or even better answer, feel free to post it here to support the asking persons. The original poster has accepted this answer as a solution, so it was useful obviously.
You are not in the position to tell others how to answer.

Connectez-vous pour commenter.

Plus de réponses (2)

dpb
dpb le 26 Avr 2016

1 vote

Start at the beginning of <getting-started-with-matlab> and work through the tutorials to pick up basic syntax quickly...
edwinda ramadahani
edwinda ramadahani le 3 Juin 2022

0 votes

A=[1 4 2;3 1 5], B=[1 5 2;-1 0 1;3 2 4], Q=[6 1 3;-1 1 2;4 1 3]
what is the syntax for (BA)+Q

1 commentaire

If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
You also posted your question as an answer.
As to your question; there are two options of what you could mean, both shown below. Neither works, for different reasons.
A=[1 4 2;3 1 5];
B=[1 5 2;-1 0 1;3 2 4];
Q=[6 1 3;-1 1 2;4 1 3];
try
(B*A)+Q
catch ME,warning(ME.message),end
Warning: Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.
try
(B.*A)+Q
catch ME,warning(ME.message),end
Warning: Arrays have incompatible sizes for this operation.

Connectez-vous pour commenter.

Produits

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by