Replace table elements in more than one row

Technical Source
2 min readMar 29, 2023

--

Hi,

I have outputted a vector (V) which contains the row indices of elements in a table (T) that contain the string ‘rpm’.

T has 3 columns and I initially set all of the elements in column 3 to zero. I now wish to replace all elements in column 3 that have these row indices (so only row 3 and row 7) with a value of 6. I have tried doing this but it doesn’t work:

V = [3;7]; % row indices
for i = 1:numel(V) T(V(i), 3) = repmat(6, numel(V), 1);end

I get an error saying To assign to or create a variable in a table, the number of rows must match the height of the table.

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

You should look into how MATLAB does its indexing. You don’t have to loop through the array to change a value. Just do it like this:

T = zeros(10,3); %i just picked 10 rows of data
indx = [3,7];
T(indx,3) = 6
T = 10×3
0 0 0
0 0 0
0 0 6
0 0 0
0 0 0
0 0 0
0 0 6

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet