MATLAB:涉及矩阵的插值 [英] MATLAB: Interpolation that involve a matrix

查看:635
本文介绍了MATLAB:涉及矩阵的插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试插值涉及矩阵的关系,但是在设置矩阵时遇到错误 Error using .* Matrix dimensions must agree. 例如,让

I try to interpolate a relation that involve a matrix but while I am setting up it I encounter an error Error using .* Matrix dimensions must agree. For example, let

A = [1 2;3 4];
I = [1 0;0 1];
ft = linspace(0, 5, 25);
f = A.*ft + I.*ft.^2; %f is a matrix
t = [0:0.1:1];
f = interp1(ft, f, t);

f = A.*ft + I.*ft.^2;行中遇到尺寸错误.我当然知道如何使用for循环来解决这个问题.但是我不想做一个for循环.另外,在这种情况下,我无法进行插值.如何解决这个问题?

I encounter the error of dimension in the line of f = A.*ft + I.*ft.^2;. I surely know how to get around this using for loop. But I do not want to do a for loop. Also, in this case I cannot do interpolation. How to get around with this problem?

推荐答案

您正在使用.*,它是标量乘法,因此会出现错误,因为您尝试对具有不同大小的矩阵进行按元素运算(对于A v 为2 * 2,对于ft为1 * 25).

You are using .*, which is scalar multiplying, so you get an error because you try do do an element-wise operation on matrices that have different size (2*2 for A v 1*25 for ft).

我想您真正想要的是并排设置(0 * A,0.04 * A,0.08 * A,...,0.96 * A,1 * A).如果是这样,您应该考虑使用简单的for循环并逐步填充ft.

I guess what you really want is to set up side by side (0*A, 0.04*A, 0.08*A, ..., 0.96*A, 1*A). If so, you should consider using a simple for loop and fill ft step by step.

此功能也可能如果您不惜一切代价避免循环,请帮助我,让我知道如何解决

This function may also help you if you want at all cost avoid the loop, let me know how that worked out

这篇关于MATLAB:涉及矩阵的插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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