0
*我需要的输出是一个矩阵,因为代码的一个更大的部分需要这段代码的输出是一个矩阵,它的输入*在数组中保持相同的顺序 - Brain Teaser?
你好。我有一个与矩阵操纵有关的问题。
我需要在矩阵中保持相同的顺序。请参阅下面的内容,了解我正在尝试做什么。
可以说,我开始了3种水果:
fruits = {'apple','orange','berry'};
和每个水果的数量:
amount = [3,5,2]
然后第二天量改变:
amount = [2,4,3]
所以现在,我的矩阵将是:
3 5 2
2 4 3
但如果第二天我还需要增加其他水果:
fruits = {'apple','orange','berry','banana'};
和金额为:
amount = [3,4,2,1]
如何让我的新矩阵是这样的:
3 5 2 NaN
2 4 3 NaN
3 4 2 1
然后在第二天,我没有给出1个原始水果:
fruits = {'apple','berry','banana'};
和金额为:
amount = [5,1,4]
然后我需要的矩阵是这样的:
3 5 2 NaN
2 4 3 NaN
3 4 2 1
5 NaN 1 4
我怎么会写的代码,它能够处理所有这些情况?
好像你知道你的问题是什么。你试过什么了?这是非常基本的Matlab - 你会在第一天学习的东西[http://mathworks.com/videos/working-with-arrays-in-matlab-69022.html] [tutorials](http:// matlabtricks.com/post-23/tutorial-on-matrix-indexing-in-matlab)或通过查看[优秀](http://mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab .html)[documentation](http://mathworks.com/help/matlab/math/creating-and-concatenating-matrices.html)。 StackOverflow不能代替花时间自己学习。 – horchler
@horchler是的。谢谢。我想到了。 – user1681664