필터 지우기
필터 지우기

Creating an array which has the linear index of the element left of each position.

조회 수: 5 (최근 30일)
I'm trying to use MATLAB functions to creating a 9x11 array which has the linear index of the element left of each position that replaced the undefined variables with 0's. Currently I have the code to create it as a 9x10 array but am not sure how to include the row of 0's for the undefined variables to make it a 9x11 array using functions. Any help would be very much appreciated.
clearvars
clc
close all
L = reshape(1:90,9,10);
L(1,:) = zeros(1,1);

채택된 답변

Walter Roberson
Walter Roberson 2022년 10월 15일
I am not clear as to what you want to do, but
L = reshape(1:90,9,10);
L = [zeros(size(L,1),1), L]
L = 9×11
0 1 10 19 28 37 46 55 64 73 82 0 2 11 20 29 38 47 56 65 74 83 0 3 12 21 30 39 48 57 66 75 84 0 4 13 22 31 40 49 58 67 76 85 0 5 14 23 32 41 50 59 68 77 86 0 6 15 24 33 42 51 60 69 78 87 0 7 16 25 34 43 52 61 70 79 88 0 8 17 26 35 44 53 62 71 80 89 0 9 18 27 36 45 54 63 72 81 90
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 10월 15일
A different approach
L = reshape(1:90,9,10);
L(:,end+1) = 0;
L = circshift(L, [0 1])
L = 9×11
0 1 10 19 28 37 46 55 64 73 82 0 2 11 20 29 38 47 56 65 74 83 0 3 12 21 30 39 48 57 66 75 84 0 4 13 22 31 40 49 58 67 76 85 0 5 14 23 32 41 50 59 68 77 86 0 6 15 24 33 42 51 60 69 78 87 0 7 16 25 34 43 52 61 70 79 88 0 8 17 26 35 44 53 62 71 80 89 0 9 18 27 36 45 54 63 72 81 90

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by