Variable Matrix and replace values according to set criteria
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello
I have an issue and dont know the exact way to approach it
I want to replace the number of a column based on the values of two preceding columns and change the number it has to something else.
The matrix i have generated has 4 columns always but the number or rows is extremely big, Basically I have created a file for the use in unstructured grids, with 1st column representing node number(which may be infinite) the two subsequent columns are x-coordinate and y -coordinate, the last column is the so called flag identifier which initially is either 1 or 0
#nodes x y flag
1 -11 60 0
2 -11 61 1
3 -10 61 1
4 -11 60.5 2
...etc
What i want to do is, to set a criterion that will instruct based on a standard x-value coordinateand a variable y-value coordinate and replace the flag (4th column with another number either 2,3, 4).
Often i want to have a steady value of x criterion and detect all the correspoding coordinates and change the final column.
for example i want to have x=-11 and then any y coordinate from y=60 to 61 has to be detected and the flag column to be changed into 2, so the new format of my file will be
1 -11 60 2
2 -11 61 2
3 -10 61 1
4 -11 60.5 2
I thought to use one approach I had in one of my trials, when i wanted to visuallize and separate my grid, but i dont think this will work now and somehow use IS function
d(:,4)==0;
% find which # nodes have the 0 or 1 as last column and classify it into a table A
A=find(d(:,4)==0);
% create a table that will include only the values that had 0 or 1 at their erd column and give me in the two other columns the values % d1=new table
% d= original table
% A=table with #nodes containing the nodes with 0
% 1:2= give the values for the nodes with 0 and give columns 1&2
d_0=d(A,1:2:3:4); %
Any help and suggestions please??
kind regards
George
0 Commenti
Risposte (2)
Jos (10584)
il 7 Mar 2014
logical indexing will help you
d = [1 -11 60 0 ; 2 -11 61 1 ; 3 -10 61 1 ; 4 -11 60.5 2]
tf = d(:,2) == -11 & (d(:,3)>=60 | d(:,3)<=61)
d(tf,4) = 2
Iain
il 7 Mar 2014
matrix = [# x y f];
matrix(matrix(:,2) > 4,4) = 4; % This sets all the flags, where x is greater than 4, to 4.
matrix(matrix(:,2) > 4 & matrix(:,2) < 5,4) = 4; % This sets all the flags, where x is greater than 4 and x is less than 5, to 4.
matrix(matrix(:,3) > 4 & matrix(:,2) < 5,4) = 4; % This sets all the flags, where y is greater than 4 and x is less than 5, to 4.
Hopefully you get the idea ;)
1 Commento
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!