Azzera filtri
Azzera filtri

Shifting cells to the right in the header of array

3 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Walter Roberson
Walter Roberson il 6 Nov 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 Commento
Wouter Wizard
Wouter Wizard il 6 Nov 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!

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by