do I just use datetime or is it more complicated than that?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Undoing a Tony's Trick
1 view (last 30 days)
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
Image Analyst
on 4 Mar 2021
I have no idea what it even is. Who is Tony, and what is his trick? 🤔
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.
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
I had a variable which I named datafi which had 16 cells (they are tables) of data. Each of the cells (table 1, 2, 3, 4... 16...) had a date/time vector for when chlorophyll was taken over a time period. I used Tony's Trick to make date/time on those table the same as the first date/time listed on each of those tables. I did this to run some codes for "cleaning the data" to make it easier for for loops and doing what I want to . Now that I'm trying to find the depth that is associated with certain time points, I need to convert the date back to its original form (but obviously I still want to use the "cleaned data") not the original data -which I could have pulled the original date/time from, but that data is messy.
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
I'm trying to write a for loop that finds the max depth per hour and the time associated with it. The time is found in databin{}.Var1 and depth is databin{}.Var7. However, date is all the same since I used Tony's trick originally so I could clean the data. I want to eventually get a speed by finding the difference between each depth change and time change (distance traveled over time it took). I'm trying to find a species swimming speed in the water column by using the distance they travel up and down the water column and the time it takes them. The data in datafi, 16 tables, is the data from one cast and the species movement over a 24 hour time period.
for i=1:length(databin);
temp=databin{i};
temp=temp(:,Varnum1);
% time=databin{i};
% time=time(:,datafi.Var{1}); problem with time because its all the
% same
depth=databin{i};
depth=depth(:,Varnum2);
depthdif = diff(depth(1:end -1));
timedif(i)= diff(time(1:end-1));
ss = timedif(i)/depthdif(i); %%%theres no difference in time
end
Answers (0)
See Also
Categories
Find more on Tables 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia-Pacífico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)