I have a matrix A 335×5 and I'm extracting 2nd and 3rd column from the matrix with the corresponding number. Currently, the program looks like this:
fileID = fopen('XY_Position.txt','w');for i=1:nodes fprintf(fileID,'%d,%.4f,%.4f\n',i,A(i,2),A(i,3));endfclose(fileID);
The output is:
1,355.3035,176.97552,353.8089,176.17073,352.1992,175.48084,350.7045,174.90595,344.1509,173.52626,338.0571,173.06637,332.8832,172.95138,330.2387,172.4914etc
Now I need to include a condition where if, A(current row,4) Not Equal to A(next row,2), then extract elements A(current row,4) and A(current row,5). Please refer to the example below to understand the problem better.
For instance, we have a matrix:
22 305.2889 146.0469 306.5536 142.367723 306.5536 142.3677 301.6096 140.298124 301.6096 140.2981 299.0802 139.033325 299.0802 139.0333 297.0106 138.228526 518.2249 225.1505 507.1871 230.324527 507.1871 230.3245 505.0026 236.763128 505.0026 236.7631 503.5079 239.9825
As can be seen, the element A(current row, 4) is equal to A(next row,2), EXCEPT row 25 and 26.
The output is expected to be:
22,305.2889,146.046923,306.5536,142.367724,301.6096,140.298125,299.0802,139.033326,297.0106,138.228527,518.2249,225.150528,507.1871,230.324529,505.0026,236.7631
Please ask questions if problem is not clear enough. Your help is greatly appreciated.
Thank you.
Best Answer