Subtraction of a constant from a matrix column

42 次查看(过去 30 天)
Hi all, I'm trying to subtract a constant from every element in a matrix column, as the title suggests. The code I have is the following, however it does not work:
ver(:,1) = ver(:,1)-X;
Example. If we take ver = [1 2 3 ; 4 5 6], and X=3. So what I want to get by this subtraction is ver = [-2 2 3 ; 1 5 6].
Any help is appreciated. Thanks in advance! Cheers!

回答(2 个)

KL
KL 2017-10-5
编辑:KL 2017-10-5
It works for me
>> ver = [1 2 3 ; 4 5 6]
X = 3
ver =
1 2 3
4 5 6
X =
3
>> ver(:,1) = ver(:,1)-X
ver =
-2 2 3
1 5 6
What do you mean by it doesn't work?

SUJEET KUMAR
SUJEET KUMAR 2023-9-15
how to sum the all element in matric

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by