更新:合并两个数组Matlab的 [英] Update : Merge two arrays Matlab

查看:720
本文介绍了更新:合并两个数组Matlab的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题的的更新版本合并两个数组Matlab的

假设现在两个数组

    A1 = [x1 y1
          x2 y2
          x3 y3
          0  0
          0  0
          0  0
          0  0
          0  0
              ]

   A2 = [a1 b1
          a2 b2
          a3 b3
          a4 b4
          0  0
          0  0
          0  0
              ]

现在,如何合并A1和A2在最短的方式,这样

Now, how to merge A1 and A2 in the shortest way, such that

   A = [x1 y1
        x2 y2
        x3 y3
        a1 b1
        a2 b2
        a3 b3
        a4 b4
        0  0]

早期的答案是正确的,它会删除所有的零。但如何通过索引的最短途径achiev这一点,类似previous答案?

The earlier answer was correct and it removes all the zeros. But how to achiev this in the shortest way by indexing , similar to the previous answer?

更新:

这是我的尝试
从previous使用问题的答案

This is what I tried Using the answer from the previous question

    A=[A1(max(A1')>0,:);A2(max(A2')>0,:)]
    A = padarray(A,[size(A1,1) - size(A,1) 0],'post')

这是pretty微不足道,但正如我在我的问题显然提到,是否有一行答案或能达到这个像previous问题的命令?我的主要目的是扩大对如何有效地使用MATLAB和行为的索引优势,为他人以及谁将会遇到这个问题,有很多建议它可能有一个指导我的知识基础。

It is pretty trivial, but as I have mentioned in my question clearly, is there an one line answer or a command that can achieve this like the previous question? My main aim is to expand my knowledge base on how to effectively use the indexing advantage of matlab and act as a guide for others as well who will come across this question, with many suggestions it may have.

谢谢,
LN

Thanks, LN

推荐答案

如何

A2(length(A1),2) = 0;
A = A1 + circshift( A2,find(A1(:,1),1,'last'))

这篇关于更新:合并两个数组Matlab的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆