Issue with different length of columns in a matrix.

1 vue (au cours des 30 derniers jours)
Chathu
Chathu le 7 Mai 2016
Commenté : Chathu le 9 Mai 2016
x,y and z coordinates of a particular image has been saved as a matrix, by using the following code:
[x,y]=find(any(A,3)); % A is the variable which x and y coordinates are saved in.
xyz = [x, y];
xyz(:,1) =xyz(:,1).*0.0003; % multiplied by a calibration factor
xyz(:,2) =xyz(:,2).*0.0003; % -do-
xyz(:,3) = 2; % add the z coordinate to the matrix
save('A_new.mat', 'xyz','-v7','-append') % save the xyz variable
Here is the output which i am getting for the above code:
X extent: 0 to 1576
Y extent: 0 to 1894
Z extent: 0 to 9
Note: z column is added to the x and y column by appending it. My question is why i am getting a low length for the z column (why is it upto 9 instead of being 1576) Can anyone help me to resolve this matter?
  6 commentaires
Image Analyst
Image Analyst le 8 Mai 2016
Column 3, which you consider as Z, is the same length as the first two columns, not different. You do not show us the code that generated these lines in the command window:
X extent: 0 to 1576
Y extent: 0 to 1894
Z extent: 0 to 9
So what Walter says still holds. There is no line that some something like
extentHighZ = ....whatever....
fprintf('X Extent: %d to %d', extentLowX, extentHighX);
fprintf('Y Extent: %d to %d', extentLowY, extentHighY);
fprintf('Z Extent: %d to %d', extentLowZ, extentHighZ);
Chathu
Chathu le 9 Mai 2016
Image Analyst,kindly see my comment below.(sorry if i confuse you here) In fact,(for the favor of other readers) i have to say that the code in the question gives the same coordinate lengths for xyz(:,1),xyz(:,2),and xyz(:,3). X extent: 0 to 1576 Y extent: 0 to 1894 Z extent: 0 to 9 ABove output is not from MatLab (though i was confuse with Paraview extensions, you'll shouldn't be confuse at all) and their extensions have nothing to do with MatLab. So the problem solved ! Thank you.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 8 Mai 2016
You made the extremely common beginner mistake of thinking row,column is the same as x,y. It is NOT. You should have
[y, x] = find(any(A, 3));
Look up find() the in help and you'll see it returns [rows, columns], which is [y, x], not [x,y].
  4 commentaires
Image Analyst
Image Analyst le 8 Mai 2016
Well, I didn't run the code and I doubt it was the root cause of the problem, but it was wrong. Usually that kind of thing shows up in something they plot or display being "turned sideways" from what they were expecting. I'm still waiting for an answer to Walter's and my comment/question above.
Chathu
Chathu le 9 Mai 2016
@ dpb , @ Image Analyst, & @ Walter First, i am extremely sorry for replying you late than usual. But all your efforts and advice are immeasurable . Second, my intention is to generate a 3D model. Below section is Not from MatLab instead from Paraview.
X extent: 0 to 1576
Y extent: 0 to 1894
Z extent: 0 to 9
( i add Paraview's OP thinking that my question looks clearer if i add it{unfortunately, that's not what happened} and i totally agree that it was a huge mistake of me because i couldn't mention that OP is not from MatLab. Sorry for the confusion that i've made.And next time, i will make sure not to post other s/w OP without mentioning it properly. I agree its my fault, totally. Third,initially by looking at the extents of X,Y,Z i thought i may be doing something wrong so that's why i get different lengths. Then herecomes dpb,convince me that no matter the xyz(:,3) (which is the Z coordinate)is appended to the matrix A , still Z will have the same lengths as X and Y.I am very much thankful to dpb for his explanation earlier. Then Walter made me realize that i have obtained my desired OP already (meaning,X,Y,Z coordinates to be in the same length) which i am grateful for Walter's direction too. Then Image Analyst, pointed out a very common(but a big) mistake that i have been doing [y, x] = find(any(A, 3)); which is a huge error correction as values matter alot, at the endof the day. So Image Analyst have given a tremendous support to correct my error. All in all, three of you'll have supported me(in different view points) to correct my mistakes and overcome my issue. So finally, i agree i made couple of mistakes here and i honestly had no intention to hurt anyone.I am really sorry if i cause anyone of you any inconvenience.
.

Connectez-vous pour commenter.

Plus de réponses (1)

dpb
dpb le 7 Mai 2016
Modifié(e) : dpb le 7 Mai 2016
"length of the columns of the matrix(eg: x & y columns) vary" is not so; there will be however many of each as there are number of non-zero locations that are nonzero across all plances in A, but whatever that number is, it will be identical for every A (there simply can't be a row coordinate without it's corresponding column, iow). Hence, the third column will also be the same length as you've assigned it to all rows in the combined array via the colon operator for the rows. The end dimension of xyz is length(x)*3 == length(y)*3.
Now, A may have different dimensions in X and Y, but that's not reflected in the length of the locations but in the possible magnitude of the result for the two columns.
  2 commentaires
Chathu
Chathu le 8 Mai 2016
Modifié(e) : Chathu le 8 Mai 2016
@ dpb, thank you soo much for your response.Really appreciate it. there simply can't be a row coordinate without it's corresponding column: so true. But i wonder why i am getting an image information, as below:
X extent: 0 to 1576
Y extent: 0 to 1894
Z extent: 0 to 9
I want to extend the Z upto the length of X or Y . For this example, i would like to extend upto the length of X. I think below line (which you wrote) is for that, correct?
length(x)*3 == length(y)*3
Suppose i want to extend the Z column to the shortest length either X or Y. How to do that? Also, i wonder why i am getting a very low value for Z. Any ideas? Hope to hear your feedback. Thanks again for your response earlier.
dpb
dpb le 8 Mai 2016
There's no way the code snippet shown can generate that output; the variables in the code are x, y, and xyz from the 3D array A.
Perhaps A contains those values in each dimension; perhaps there's some function that writes the equivalent of the output of size() or somesuch but we can't see that from what you've posted; I've no klew what gives the above message, sorry.
I presume the answer is related to the size(A) but what precisely "extent" refers to here is unknown.
And, no, the expression length(x)*3 == length(y)*3 doesn't do any such thing, I was simply writing that as your code exists the two array sizes are the same; it was intended as an algebraic truth, not as code.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by