Shifting cells to the right in the header of array

조회 수: 7 (최근 30일)
Wouter Wizard
Wouter Wizard 2019년 11월 6일
댓글: Wouter Wizard 2019년 11월 6일
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