Shifting cells to the right in the header of array

3 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2019-11-6
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 个评论
Wouter Wizard
Wouter Wizard 2019-11-6
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!

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by