error using conv

I get error when using conv function
dataset=[10 89 87 56 28 96 58 ;1 5 70 59 30 18 25 ;14 20 89 87 100 54 20]
i want to find mid point for example
A=[3 5 6 15 17 21 35 45 46 51 56 57 66 70 71]'
i get answer as
4.0000
5.5000
10.5000
16.0000
19.0000
28.0000
40.0000
45.5000
48.5000
53.5000
56.5000
61.5000
68.0000
70.5000
using code F_mid = conv(A, [0.5 0.5], 'valid')
when i use this code for my dataset
i get error
Error using ==> conv at 27
A and B must be vectors.
Error in ==> new at 3
F_mid = conv(F, [0.5 0.5], 'valid')
please help

 采纳的回答

The code you show that you are using is
F_mid = conv(A, [0.5 0.5], 'valid')
but your error message is for
F_mid = conv(F, [0.5 0.5], 'valid')
which does not occur anywhere in the code you show.
We do not have any information about the shape of F.

9 个评论

Error using ==> conv at 27
A and B must be vectors.
Error in ==> new at 3
F_mid = conv(F, [0.5 0.5], 'valid')
F is mt dataset
dataset=[10 89 87 56 28 96 58 ;1 5 70 59 30 18 25 ;14 20 89 87 100 54 20]
And is your "dataset" variable a vector like the error message says is required?
conv() is for 1D convolution. If you want 2D convolution, then use a 2D convolution function such as conv2(), probably with [0.5 0.5].' as your kernel. Or if you want each column to be done independently, then make one conv() call per column.
arrayfun(@(IDX) conv(F(:,IDX),[0.5 0.5]), 1:size(F,2))
thanks walter
in ur code
reshape(F, 2, []).'
F = 3 5 6 15 17 21 35 45 46 51 56 57 66 70 71
the output is is
3 5
6 15
17 21
but i need as
3 5
5 6
6 15
i need same for dataset also
That's a different question and Andrew provided a solution for that.
Note however that your F is *not* a vector or else you would not be having problems passing it to conv(). You have not defined how you want to handle splitting matrices.
I do not see any connection between the two questions, other than that they use the same variable name "F" (for two different purposes.) Unless, that is, you are trying to find a way other than using conv() to find the midpoints.
error in using Error using ==> arrayfun
arrayfun(@(IDX) conv(F(:,IDX),[0.5 0.5]), 1:size(F,2))
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Error in ==> new at 7
arrayfun(@(IDX) conv(F(:,IDX),[0.5 0.5]), 1:size(F,2))
arrayfun(@(IDX) conv(F(:,IDX),[0.5 0.5],'valid'), 1:size(F,2))
walter i get same error for my dataset
Whatever. Use a "for" loop then. Or use conv2()

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by