Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Resources/Suggestions for dealing with small slightly irregular arrays. Cell Array? (Edited)

1 回表示 (過去 30 日間)
Douglas Anderson
Douglas Anderson 2018 年 12 月 8 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello,
I would like some suggestions on how to deal with (numbering, calculating, etc.) small arrays (such as 4 x 20) that will have elements deleted.
For instance, starting with
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
then user deleting some, how to deal with the elements of an array like
1 2 3 4 5 6 7
8 9 10 11 12 13
14 15 16 17 18
How do you renumber, and then want to have these numbers associated with other data? You can't mathematically manipulate a cell array like you can a standard array
% Script for slightly non-rectangular small array
num_holes = 7;
num_rows = 3;
total_holes = num_holes * num_rows;
x = 1:total_holes;
hole_array = reshape(x,num_holes,num_rows)'
flipped_hole_array = fliplr(hole_array)
flipped_cell_array = num2cell(flipped_hole_array)
flipped_cell_array{2,1} = [];
flipped_cell_array{3,1} = [];
flipped_cell_array{3,2} = [];
flipped_cell_array
Thanks.
  2 件のコメント
James Tursa
James Tursa 2018 年 12 月 8 日
How will this be used downstream in your code? You can't have non-rectangular data in variables (full or sparse). Maybe you need to use a cell array. Is the data always going to be non-zero?
Douglas Anderson
Douglas Anderson 2018 年 12 月 8 日
James -- should have put this in a comment:
Hello James, and thank you.
Simply put, this is an "array" (in the loosest terms) of points on a grid that is almost rectangular. It starts out rectangular, and the user may delete some of them, making it non-rectangular. The points are independent (have data associated with them), except that the numbering of the points needs to be contiguous, like in the above example. Sometimes the numbering starts at the left, sometimes at the right, and sometimes in the middle (I've already figured that out for the full rectangle. I can use fliplr() or various colon combinations). It's just the oddball things with a couple of removed points that make the NUMBERING the big problem. I have a "kill_me()" function to delete the points.
Hope that helps. If you want to know more, let me know!

回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by