storing a vector in a sequential manner

Home Forums Matlab storing a vector in a sequential manner

Tagged: ,

This topic contains 3 replies, has 2 voices, and was last updated by  samuelsuhas1991 9 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #525

    samuelsuhas1991
    Participant

    Dear Sir, Suppose i want to multiply a scalar with a vector and store it in a sequential manner. how to do that?

    for example.
    a=[1 -1; -1 1];
    b=[10; 5; 4; 3; 7; 6; 2];
    c1 = b(1,1).*a;
    c2 = b(2,1).*a;
    c3 = b(3,1).*a;
    .
    .
    cn = b(n,1).*a;
    without repeating the sequence, how to store it in a variable starting with the same letter all the time. As i cannot store it as c(i) in for loop as c1 is a matrix.
    and access the variable c for some other operation.

    #527

    samuelsuhas1991
    Participant

    dear sir, i got the solution for this by using the array indexing. which is like c{i}.

    However, i’m unable to index the elements of the iterated array.

    example: c{1} = [1 2;3 4] and c{2} = [5 6; 7 8];

    how to add the 1st row 1st column element of c{1} to 1st row 1st column element of c{2} ???

    #528

    cK
    Keymaster

    If you meant assignment:
    c{2}(1,1) = c{1}(1,1)
    Please see other posts on indexing in cells.
    To add, just replace = with +

    • This reply was modified 9 years, 7 months ago by  cK.
    #530

    samuelsuhas1991
    Participant

    thank u sir. your solution is helpful.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.