# Zero a cell matrix with varying number of zeros

3 ビュー (過去 30 日間)
Mohammed Kagalwala 2019 年 10 月 30 日
コメント済み: ME 2019 年 10 月 31 日
Hi,
I have a cell matrix, C, that's n x n, and an array A of size n x 1. The entries of array A dictate the no. of column of zeros in the matrix M.
i.e. M1 has a dimension 6 x A(1), M2 has a dimension 6 x A(2)
Given an index i, what I wish to do is the following,
Column i of C is filled with matrix Mi of dimension 6xA(i). So all n entries in column i are replaced with a matrix of zeros.
I know the following code
C(:,:) = {zeros(3,3)}
will give me zeros eveyrwhere, I want to leverage similar syntax to solve my problem. Avoiding the use of for loops.
Thank you.

サインインしてコメントする。

### 回答 (1 件)

ME 2019 年 10 月 30 日
I'm not 100% sure I follow, but as I understand you want to take some list of columns and turn all elements in that column to zeros?
If so then you could use something like:
C(:,cols) = 0
where cols is an array containing the indices of the columns to be zeroed. For example setting cols = [1 3] would put zeros in the first and thrid columns.
If that's not what you meant then please could you explain some more?
##### 6 件のコメント4 件の古いコメントを表示4 件の古いコメントを非表示
Mohammed Kagalwala 2019 年 10 月 30 日
C is a cell of a fixed size nxn. Each cell column will have a unique size based on A. i.e. something like this,
In this case A = [5 1 5 10 8 8 8 8 9 8 10 2].
This was however created using a for loop. I want to make this same cell structure without the use of for loops.
ME 2019 年 10 月 31 日
Oh, I see! Sorry, I completely missed the fact you wanted to do this inside a cell array. I don’t have a good answer for you right now but I’ll have a think on it.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by