deleting some information in a matrix

1 回表示 (過去 30 日間)
hasan alhussaini
hasan alhussaini 2017 年 9 月 12 日
コメント済み: hasan alhussaini 2017 年 9 月 12 日
Hi i'm quite a beginner on Matlab.
basically, the following is an example of a coding im working on, I'm trying to make B have the same number of dimensions as A using the following code. e.g
%c= is going to be a randomly generated number
A = zeros(100,100);
A(25:75,25:75) = 1;
B=I(:,1:100-C)
for simplicity sake, let's say c = 30 B will have 100x70 elements, and A will have 100x100, is there a way to
  1. make B which is (100x70) have the same elements as A which is (100x100)., in other words, the elements that are not in the range are transformed into zeros?
  2. another alternative i'm thinking of making is B= A(:,C:100+C)? but I would like the new elements (the elements i'm adding e.g(101 102 103...C) to become zeros. how would you go about that?
I'm looking for answers to both these questions,
Any help would be appreciated thank you

採用された回答

Image Analyst
Image Analyst 2017 年 9 月 12 日
You can extend B by a neat trick. Simply assign the (not yet existing) lower right element:
B(size(A, 1), size(A, 2)) = 0; % Make B same size as A by appending zeros.
  1 件のコメント
hasan alhussaini
hasan alhussaini 2017 年 9 月 12 日
perfect thank you!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by