about assigning the values to a column vectors.

10 次查看(过去 30 天)
lets suppose i have 4 column vectors such as v1,v2,v3,v4
now what should i do to assign values to the elements of column v1 ( each element ) to that of vector v2.
the number of entries in both the coloumn are same.
same i want to do for v3 and v4.
and add the entries of v2 and v4 particulary for when the (v1 =~v3). the vectors here contains the numerical entries .
  5 个评论
Patel jaykumar Dipakbhai
dear sir, thankyou for your kind help, will be precise from now onwards with using words.
Screenshot (150).png
here as shown in the image EC,FC,FD,DE, are the different column vectors . and i want the addition of the elements of FC and FD, 'when the elements of EC and DE are equal'
the elements of EC have relation with FC and elements of DE have relation with FD.
therefore i was asking to assign the values to the coloumn vectors.. and add after the condition is met true( loop conditions) and those added values of would be added in the column vector 'FC'.
as you can see in the above code i have tried to get the output but i am not getting my result. kindly help if possible...
I apologize if i am harsh with using appropriate words this time too.
madhan ravi
madhan ravi 2019-7-9
Patel always post the code and the expected output so that the readers gets the grasp of your idea quickly.

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2019-7-9
As Madhan said, always post the code as text, not as pictures which we can't copy paste into matlab.
There is usually no need for table2array. Typically people use it because they don't know how to manipulate tables directly.
eq is exactly the same as ==. I suspect that you used it to try to work around some problem. It won't solve it.
If all you want to do is add the corresponding of elements of FD to FC when matching elements of |EC and DE are equal, then it's simply:
toadd = EC == DE; %logical vector
FC(toadd) = FD(toadd) + FC(toadd);
Note that all these variables are extremely poorly named. It's very easy to mistype one for the other, introducing bugs in your code, and the variable names don't mean anything. Since all these variable appear to come from the same table data, you could simply manipulate the table directly:
toadd = round(data{:, 3}) == data{:, 1};
data{toadd, 2} = data{toadd, 2} + data{toadd, 4};

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by