How to know if two or more elements are vertically aligned inside a matrix? - matlab

I have a 5x5 matrix and I need to vertically align some elements acording to some rules. For example: matrix(1,1) = 2 and matrix(5,3) = 5. The numbers 2 and 5 must be aligned in the same column, so a possible solution could be move number 2 to matrix(1,3), or move number 5 to matrix(5,1).
I know how to swap elements inside a matrix but, what is the best way to compare if two elements are in the same column?

You can get the column where a 2 is present that way:
[~,J2] = find(matrix==2)
Same thing for matrix==5. Then do the swaps that you need.

Related

How can I hide a label if another label is taking up X number of lines?

Say I have two labels, one on top of the other. Label 1 is set to have a maximum number of lines of 2 (numberOfLines=2). So sometimes, depending on the text, Label 1 can take up TWO lines. The thing though is that a maximum of 2 lines should be shown between both labels, where Label 1's second line takes precedence over Label 2. (Also, Label 2 is always 1 line.)
So either of these 2 scenarios are possible:
Label 1 text
Label 2 text
OR
Label 1 text (line 1)
Label 1 text (line 2)
The only way I thought to attack this was to simply hide Label 2 if Label 1 is taking up 2 lines. But the problem is, how can I determine how many lines Label 1 is taking up?
I've found a few other answers about this (1, 2), but none seem to work for me. Is there perhaps a better way to go about this?
In my opinion, you should just use one label, and construct the text seperately by the code and pass the final text into the label. In order to have a new line, you can use "\n". If you want to have a different fonts/color etc, you can always use AttributedString. This will be much cleaner, easier to change, and more flexible to maintain in the future.
Did you working with Constraint? or Did you have knowledge about NSLayoutConstraints?
you can easily do that with managing proper constraint and it doesn't matter how many line will text have you can show both label with text.
make sure label.numberofline = 0. // It will take line as text.

Dividing up a space evenly within a GTK# Bin

I have a custom Bin, and I wish to divide its space into two columns of equal width separated by a VSeparator. I've tried using both a Table and an HBox, but it doesn't do the trick. I don't know how to tell gtk to divide the space evenly no matter what the contents of the two columns. Setting homogeneous to true works, but that also causes the VSeparator to get way too much space.

Understanding arrays and the use of operators

I've included a photo of what I'm working on. I'm learning to code using swift playgrounds on the iPad. I'm up to arrays. In the photo I'm to build an island and add a body of water. I'm not sure if you need the entire code to understand my question. (The bottom part of the code just removes some of the land and adds water)
My question is for the part where the greater than and less than operators are being used. I don't understand what coordinate.column > 3 actually means.
If you need more info I can upload another photo with the final product and complete code.
I've added another photo of the final product and it has the remainder code with it as well. I understand that < means less than and > means greater than. But there are no columns that are less than 3 in the final product or a row greater than 8 so what makes the use of the operators work to get the water to surround the island?
Basically, the function goes through each of the tiles of your continent grid and decides if it should be kept as land (added to the island array) or transformed into water) (added to the sea array).
Let's say that your top left tile is of coordinate (0,0) (column 0 and row 0), then it goes as sea, now let's take tile (3,3), it still goes as sea as the comparison is strict (>3 not >=3), tile (5,7) is going in island and tile (8,9) is going in sea.
I guess it's worth mentioning that column and row properties are numbers (of type Int - natural (whole) numbers).
The field is represented by a grid, in your case 11x11. Each block has a two-dimensional coordinate within that grid, represented by aforementioned column and row properties.
Indexes in Swift start from 0, so when you iterate over all blocks, their column and row values can be essentially numbers from 0 to 10.
Now, what you want to do is to select bricks in the middle of the grid. If you want the island to be 4 blocks in size each dimension, you do that by comparing their coordinates. Essentially, "island in the middle of size 4 bricks each dimension" is a collection of bricks located at coordinates 4,4; 4,5; 4,6; 4,7; 5,4; 5,5; ...., 7,7.
That "if" condition that you have is merely a good way of selecting these bricks.
The > and < symbols are boolean operators, so here I am assuming that coordinate.column would return a number, and then it'll be compared for either > or < and then return true if in fact coordinate.column is < or > 8 and 3 respectively.

Putting space between bars using bar function

I am try to plot 16 bars, 8 of these belong to one group. I want to give this group the red color, the other 8 belong to another group which is given the blue color. I would like to arrange the bar in pairs, each pair containing one from the red group and one from the green group. I have tried the following:
bar(num1,info(1:2:end);
bar(num2, info(2:2:end);
in which info contains 16 values I want to plot, num1=1:2:numel(info) and num2=2:2:numel(info). If I do it this way, all the bars are placed adjacent to their neighbors and there are no gaps between bars. Ideally, to improve visualization, there should be space in between pairs but no space within a pair. For instance, bar1bar2 <space> bar3bar4 <space> bar5bar6<space>...
Could someone help me with this spacing issue? Thank you so much!
See the docs for bar. You can reshape info to 2xN (instead of its current shape 1x2N) and then use a single bar command to plot the 2 series, and it will take care of the spacing.
See this image from the docs:
If you want to keep doing it your way, you could just tweak num1 and num2:
N = numel(info) / 2;
num1 = (1:N) * 3;
num2 = (1:N) * 3 + 1;

Making one of the column dividers thicker than the others in a browse

I have a browse with 5 columns. I want the dividing line between columns 3 and 4 to be a little thicker.
Is there a way to do this?
Short answer is no, you can't change the line between columns.
But you could add an empty dummy column with blank values between column 3 and 4, that you could get to look it like a thicker separator.
Regards,