Undoing a Tony's Trick
Show older comments
Is there a specific format for undoing a Tony's trick? I used tony's trick in a for loop earlier on in my script but now I need to correlate depth values with specific times so I need to reverse the tony trick to get the original date and times back.
12 Comments
Jacqueline Chrabot
on 4 Mar 2021
Image Analyst
on 4 Mar 2021
I have no idea what it even is. Who is Tony, and what is his trick? 🤔
Paul
on 4 Mar 2021
Tony's Trick is the pre-repmat way of repeating a vector into a matrix using indexing:
>> v=[1 2 3]
v =
1 2 3
>> v(ones(3,1),:)
ans =
1 2 3
1 2 3
1 2 3
It's been called Tony's Trick forever.
Star Strider
on 4 Mar 2021
I never heard of it either by that name, and I’ve been using MATLAB for 28 years.
I’ve always done the same thing by multiplying a row vector by a column vector of ones.
Paul
on 4 Mar 2021
Tony's trick first came to light in 1990: Loren's Blog. At that time, Matlab had a function named meshdom(), which was functionally the same as today's meshgrid() and TMW changed its implementation to use Tony's trick instead of the outer product. I'm not quite sure when Tony's trick became colloquially known as "Tony's Trick," but it can't have been too much later than that.
Image Analyst
on 4 Mar 2021
Sounds like it's not needed anymore. If @Jacqueline Chrabot has a variable in some state, and she needs to manipulate it to some other state, then she should give us the variable (in a .mat file), and show us what she has and what she wants to get for the output. For example, maybe it's as simple as
v2 = v(1, :)
to use Paul's example. But don't call it "Image Analyst's Trick" since it's no trick - it's just basic indexing.
Walter Roberson
on 4 Mar 2021
Tony's Trick is the pre-repmat way of repeating a vector into a matrix using indexing:
For years, repmat was implemented by using indexing.
Adam Danz
on 4 Mar 2021
The best approach would be store your vector prior to expansion so you don't have to undo it in the first place.
David Goodmanson
on 4 Mar 2021
Edited: David Goodmanson
on 4 Mar 2021
Tony's trick is attributed to Tony Booer of Schlumberger. When a history of Matlab gets written, by all rights he should be in it.
Here's perhaps the purest example of Tony's trick
a = 6;
b = a(ones(4,5));
b =
6 6 6 6 6
6 6 6 6 6
6 6 6 6 6
6 6 6 6 6
Jacqueline Chrabot
on 5 Mar 2021
Image Analyst
on 5 Mar 2021
I agree with Adam - just save it so you'll have it when you need it again.
Otherwise, attach what you have in a .mat file and tell us what you want to obtain from that variable. It will make it so much easier for people to help you if you give us the variable you're starting with and tell us what you want as the result.
Jacqueline Chrabot
on 5 Mar 2021
Answers (0)
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!