Borrar filtros
Borrar filtros

Shifting cells to the right in the header of array

3 visualizaciones (últimos 30 días)
Wouter Wizard
Wouter Wizard el 6 de Nov. de 2019
Comentada: Wouter Wizard el 6 de Nov. de 2019
Hello everyone,
I have a problem with shifting the cells of the header in my 46x19 array with strings. The data in the array is correct, except for the first row which requires a shift to the right. I want to correct the array such that the 5th cell receives the information of the 4th cell, the 6th of the 5th and onwards until the last column number.
To solve this I have tried to create a for-loop that iterates over the column numbers, as can be seen in the code below. However, it does not change the values as I expect it to and I could not find a working solution on the internet. Can anyone help me out? Thanks!
[Rownr,Colnr] = size(gdp);
for 4:Colnr
gdp{} = gdp{1,Colnr+1};
end

Respuestas (1)

Walter Roberson
Walter Roberson el 6 de Nov. de 2019
gdp(1,5:end) = gdp(1,4:end-1);
No loop needed. Note that the content of columns 1, 2, 3, and 4 of the row will stay the same as they were.
  1 comentario
Wouter Wizard
Wouter Wizard el 6 de Nov. de 2019
Thanks for replying to quickly!
When I try the code, it says that end must be used within an array index expression. This confuses me because I thought I used end before but without such expression. I tried to find a solution to this error, but couldent find one.
Are you familiar with this error? And do you know how I can solve it?
Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by