<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Using linkaxes vs. linkprop	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-linkaxes-vs-linkprop</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Tue, 21 Dec 2021 15:58:29 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: Gabriel		</title>
		<link>https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-512695</link>

		<dc:creator><![CDATA[Gabriel]]></dc:creator>
		<pubDate>Tue, 21 Dec 2021 15:58:29 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5928#comment-512695</guid>

					<description><![CDATA[This didn&#039;t work when trying to link y axes across the plots in each column and x axes across the plots in each row on an (m x n) &lt;code&gt;tiledlayout&lt;/code&gt;.
On matlab R2021a found that I had to mix &lt;code&gt;linkaxes&lt;/code&gt; and &lt;code&gt;setappdata&lt;/code&gt;, like this:

&lt;pre lang=&quot;matlab&quot;&gt;
f = figure;
m = 2;
n = 3;
tiles = tiledlayout(f, m, n);
for i = 1:m  %rows
    for j = 1:n  %cols
        ax(i,j) = nexttile;
        plot(linspace(0,1,10)*i, linspace(2,1,10)*j);
        linkaxes(ax(:,j), &#039;y&#039;);
        setappdata(ax(i,j), &#039;XLim_listeners&#039;, linkprop(ax(i,:),&#039;XLim&#039;)); %using linkaxes(ax(i, :), &#039;x&#039;); 
    end % for all cols
end % for all rows
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>This didn&#8217;t work when trying to link y axes across the plots in each column and x axes across the plots in each row on an (m x n) <code>tiledlayout</code>.<br />
On matlab R2021a found that I had to mix <code>linkaxes</code> and <code>setappdata</code>, like this:</p>
<pre lang="matlab">
f = figure;
m = 2;
n = 3;
tiles = tiledlayout(f, m, n);
for i = 1:m  %rows
    for j = 1:n  %cols
        ax(i,j) = nexttile;
        plot(linspace(0,1,10)*i, linspace(2,1,10)*j);
        linkaxes(ax(:,j), 'y');
        setappdata(ax(i,j), 'XLim_listeners', linkprop(ax(i,:),'XLim')); %using linkaxes(ax(i, :), 'x'); 
    end % for all cols
end % for all rows
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yaroslav		</title>
		<link>https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-434793</link>

		<dc:creator><![CDATA[Yaroslav]]></dc:creator>
		<pubDate>Thu, 09 Aug 2018 07:52:10 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5928#comment-434793</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-434667&quot;&gt;Mark D.&lt;/a&gt;.

@Mark, the &lt;b&gt;&lt;code&gt;zoom&lt;/code&gt;&lt;/b&gt; function calls &lt;b&gt;&lt;code&gt;resetplotview&lt;/code&gt;&lt;/b&gt; (undocumented). It, in turn, resets  all modes (&lt;code&gt;X/YLimMode&lt;/code&gt;) to &lt;code&gt;auto&lt;/code&gt;. That is why the listeners do not trigger. 

To solve the issue, link these properties too:
&lt;pre lang=&quot;matlab&quot;&gt;linkprop([a1 a2],{&#039;XLimMode&#039;,&#039;YLimMode&#039;}); % trigger linking on double click&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-434667">Mark D.</a>.</p>
<p>@Mark, the <b><code>zoom</code></b> function calls <b><code>resetplotview</code></b> (undocumented). It, in turn, resets  all modes (<code>X/YLimMode</code>) to <code>auto</code>. That is why the listeners do not trigger. </p>
<p>To solve the issue, link these properties too:</p>
<pre lang="matlab">linkprop([a1 a2],{'XLimMode','YLimMode'}); % trigger linking on double click</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Mark D.		</title>
		<link>https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-434667</link>

		<dc:creator><![CDATA[Mark D.]]></dc:creator>
		<pubDate>Wed, 08 Aug 2018 11:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5928#comment-434667</guid>

					<description><![CDATA[@Yaroslav your solution works great, but the double mouseclick (of zoom out or zoom in), which puts the plot in the default optimized axes, doesn&#039;t work or behaves the same, instead of just linking by linkaxes. Do you know the solution for that too?

&lt;pre lang=&quot;matlab&quot;&gt;
x = 1:5;
y = randn(1,5);

figure;
a1 = subplot(1,2,1);
p1 = plot(x,y);

a2 = subplot(1,2,2);
p2 = plot(y,x);

addlistener(a1,&#039;XLim&#039;,&#039;PostSet&#039;,@(~,~)set(a2,&#039;YLim&#039;,get(a1,&#039;XLim&#039;))); % link a1.XLim to a2.YLim
addlistener(a1,&#039;YLim&#039;,&#039;PostSet&#039;,@(~,~)set(a2,&#039;XLim&#039;,get(a1,&#039;YLim&#039;))); % link a1.YLim to a2.XLim
% and vice versa
addlistener(a2,&#039;XLim&#039;,&#039;PostSet&#039;,@(~,~)set(a1,&#039;YLim&#039;,get(a2,&#039;XLim&#039;))); % link a1.XLim to a2.YLim
addlistener(a2,&#039;YLim&#039;,&#039;PostSet&#039;,@(~,~)set(a1,&#039;XLim&#039;,get(a2,&#039;YLim&#039;))); % link a1.YLim to a2.XLim

%Use case, Zoom about 4 Times in and zoom out per doubleclick an you will see, that it then doesn&#039;t update the axes
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>@Yaroslav your solution works great, but the double mouseclick (of zoom out or zoom in), which puts the plot in the default optimized axes, doesn&#8217;t work or behaves the same, instead of just linking by linkaxes. Do you know the solution for that too?</p>
<pre lang="matlab">
x = 1:5;
y = randn(1,5);

figure;
a1 = subplot(1,2,1);
p1 = plot(x,y);

a2 = subplot(1,2,2);
p2 = plot(y,x);

addlistener(a1,'XLim','PostSet',@(~,~)set(a2,'YLim',get(a1,'XLim'))); % link a1.XLim to a2.YLim
addlistener(a1,'YLim','PostSet',@(~,~)set(a2,'XLim',get(a1,'YLim'))); % link a1.YLim to a2.XLim
% and vice versa
addlistener(a2,'XLim','PostSet',@(~,~)set(a1,'YLim',get(a2,'XLim'))); % link a1.XLim to a2.YLim
addlistener(a2,'YLim','PostSet',@(~,~)set(a1,'XLim',get(a2,'YLim'))); % link a1.YLim to a2.XLim

%Use case, Zoom about 4 Times in and zoom out per doubleclick an you will see, that it then doesn't update the axes
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370823</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 01 Mar 2016 07:58:05 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5928#comment-370823</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370818&quot;&gt;Yaroslav&lt;/a&gt;.

@Yaroslav - you are correct, I was misled by the wording of &lt;i&gt;&lt;b&gt;linkprop&lt;/b&gt;&lt;/i&gt;&#039;s documentation:

&lt;blockquote&gt;&quot;...maintain the same values for the corresponding properties of different graphics objects.&quot;&lt;/blockquote&gt;

Serves me right to trust the builtin documentation! - I should have known better... :-)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370818">Yaroslav</a>.</p>
<p>@Yaroslav &#8211; you are correct, I was misled by the wording of <i><b>linkprop</b></i>&#8216;s documentation:</p>
<blockquote><p>&#8220;&#8230;maintain the same values for the corresponding properties of different graphics objects.&#8221;</p></blockquote>
<p>Serves me right to trust the builtin documentation! &#8211; I should have known better&#8230; 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yaroslav		</title>
		<link>https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370818</link>

		<dc:creator><![CDATA[Yaroslav]]></dc:creator>
		<pubDate>Tue, 01 Mar 2016 06:43:52 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5928#comment-370818</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370580&quot;&gt;Amin&lt;/a&gt;.

@Yair -- I am afraid that your solution doesn&#039;t answer @Amin&#039;s question. It, actually, behaves almost exactly as &lt;pre lang=&quot;matlab&quot;&gt;
linkaxes([hAxes1 hAxes2], &#039;xy&#039;);
&lt;/pre&gt;
@Amin -- If you want to link two different properties, you must specify the listeners explicitly. For example, &lt;pre lang=&quot;matlab&quot;&gt;
addlistener(hAxes1,&#039;XLim&#039;,&#039;PostSet&#039;,@(~,~)set(hAxes2,&#039;YLim&#039;,get(hAxes1,&#039;XLim&#039;))); % link hAxes2.YLim to hAxes1.XLim
addlistener(hAxes1,&#039;YLim&#039;,&#039;PostSet&#039;,@(~,~)set(hAxes2,&#039;XLim&#039;,get(hAxes1,&#039;YLim&#039;))); % link hAxes2.XLim to hAxes1.YLim
addlistener(hAxes2,&#039;XLim&#039;,&#039;PostSet&#039;,@(~,~)set(hAxes1,&#039;YLim&#039;,get(hAxes2,&#039;XLim&#039;))); % link hAxes1.YLim to hAxes2.XLim
addlistener(hAxes2,&#039;YLim&#039;,&#039;PostSet&#039;,@(~,~)set(hAxes1,&#039;XLim&#039;,get(hAxes2,&#039;YLim&#039;))); % link hAxes1.XLim to hAxes2.YLim
&lt;/pre&gt;
The &lt;code&gt;linkprop&lt;/code&gt; function won&#039;t do, since it links &lt;i&gt;the same&lt;/i&gt; property between two different handle objects.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370580">Amin</a>.</p>
<p>@Yair &#8212; I am afraid that your solution doesn&#8217;t answer @Amin&#8217;s question. It, actually, behaves almost exactly as </p>
<pre lang="matlab">
linkaxes([hAxes1 hAxes2], 'xy');
</pre>
<p>@Amin &#8212; If you want to link two different properties, you must specify the listeners explicitly. For example, </p>
<pre lang="matlab">
addlistener(hAxes1,'XLim','PostSet',@(~,~)set(hAxes2,'YLim',get(hAxes1,'XLim'))); % link hAxes2.YLim to hAxes1.XLim
addlistener(hAxes1,'YLim','PostSet',@(~,~)set(hAxes2,'XLim',get(hAxes1,'YLim'))); % link hAxes2.XLim to hAxes1.YLim
addlistener(hAxes2,'XLim','PostSet',@(~,~)set(hAxes1,'YLim',get(hAxes2,'XLim'))); % link hAxes1.YLim to hAxes2.XLim
addlistener(hAxes2,'YLim','PostSet',@(~,~)set(hAxes1,'XLim',get(hAxes2,'YLim'))); % link hAxes1.XLim to hAxes2.YLim
</pre>
<p>The <code>linkprop</code> function won&#8217;t do, since it links <i>the same</i> property between two different handle objects.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370638</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 27 Feb 2016 16:42:35 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5928#comment-370638</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370580&quot;&gt;Amin&lt;/a&gt;.

@Amin - I believe that you can link multiple properties/handles for example:
&lt;pre lang=&quot;matlab&quot;&gt;linkprop([hAxes1,hAxes2], {&#039;XLim&#039;,&#039;YLim&#039;})&lt;/pre&gt;
aught to link hAxes1.XLim to hAxes2.YLim]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370580">Amin</a>.</p>
<p>@Amin &#8211; I believe that you can link multiple properties/handles for example:</p>
<pre lang="matlab">linkprop([hAxes1,hAxes2], {'XLim','YLim'})</pre>
<p>aught to link hAxes1.XLim to hAxes2.YLim</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Amin		</title>
		<link>https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-370580</link>

		<dc:creator><![CDATA[Amin]]></dc:creator>
		<pubDate>Fri, 26 Feb 2016 16:50:38 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5928#comment-370580</guid>

					<description><![CDATA[Amazing post Yair. Thanks!

One question though. Is it possible to link two different properties? For example  &#039;x-axis&#039; of an ax to &#039;x-axis&#039; and &#039;y-axis&#039; of another ax?]]></description>
			<content:encoded><![CDATA[<p>Amazing post Yair. Thanks!</p>
<p>One question though. Is it possible to link two different properties? For example  &#8216;x-axis&#8217; of an ax to &#8216;x-axis&#8217; and &#8216;y-axis&#8217; of another ax?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yaroslav		</title>
		<link>https://undocumentedmatlab.com/articles/using-linkaxes-vs-linkprop#comment-353649</link>

		<dc:creator><![CDATA[Yaroslav]]></dc:creator>
		<pubDate>Fri, 24 Jul 2015 12:48:53 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5928#comment-353649</guid>

					<description><![CDATA[Hi @Yair,

The solution you proposed with &lt;code&gt;linkprop&lt;/code&gt; has a small issue: it does not restore the linking after saving and reloading.  On the other hand, &lt;code&gt;linkaxes&lt;/code&gt; recovers its linking correctly.

A simple workaround is to use Matlab&#039;s own solution: &quot;&lt;i&gt;MCOS graphics cannot rely on custom machinery in hgload to restore linkaxes. Instead, create a matlab.graphics.internal.LinkAxes to wrap the linkprop which will restore the linkaxes when it is de-serialized.&lt;/i&gt;&quot; In simple words,
&lt;pre lang=&quot;matlab&quot;&gt;
% Link the relevant axes
restorable_linkprop = @(varargin)matlab.graphics.internal.LinkAxes(linkprop(varargin{:}));
%
setappdata(ax(1,1), &#039;YLim_listeners&#039;, restorable_linkprop(ax(1,:),&#039;YLim&#039;));
setappdata(ax(2,1), &#039;YLim_listeners&#039;, restorable_linkprop(ax(2,:),&#039;YLim&#039;));
setappdata(ax(1,1), &#039;XLim_listeners&#039;, restorable_linkprop(ax(:,1),&#039;XLim&#039;));
setappdata(ax(1,2), &#039;XLim_listeners&#039;, restorable_linkprop(ax(:,2),&#039;XLim&#039;));

&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Hi @Yair,</p>
<p>The solution you proposed with <code>linkprop</code> has a small issue: it does not restore the linking after saving and reloading.  On the other hand, <code>linkaxes</code> recovers its linking correctly.</p>
<p>A simple workaround is to use Matlab&#8217;s own solution: &#8220;<i>MCOS graphics cannot rely on custom machinery in hgload to restore linkaxes. Instead, create a matlab.graphics.internal.LinkAxes to wrap the linkprop which will restore the linkaxes when it is de-serialized.</i>&#8221; In simple words,</p>
<pre lang="matlab">
% Link the relevant axes
restorable_linkprop = @(varargin)matlab.graphics.internal.LinkAxes(linkprop(varargin{:}));
%
setappdata(ax(1,1), 'YLim_listeners', restorable_linkprop(ax(1,:),'YLim'));
setappdata(ax(2,1), 'YLim_listeners', restorable_linkprop(ax(2,:),'YLim'));
setappdata(ax(1,1), 'XLim_listeners', restorable_linkprop(ax(:,1),'XLim'));
setappdata(ax(1,2), 'XLim_listeners', restorable_linkprop(ax(:,2),'XLim'));

</pre>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
