Simple subtraction from column/row - HELP

12 views (last 30 days)
Leighton on 17 Nov 2014
Commented: Leighton on 18 Nov 2014
Hello, let me first introduce myself. I am a 32 (nearly 33) year old mature student in my final year of engineering study.
Secondly, I am a complete NOVICE when it comes to matlab but have chosen this module during my final year of study as I believe matlab will benefit me more in the future as opposed to CFD (for example) or stress analysis via a CAD package!
Anyway, I have an issue which I can't seem to iron out...
Brief description of what I am trying to do;
Am compiling a matrix [m,n] (in my current example, is [4, 7]) and need to subtract a constant from each column in a linear manner.
Using the 3x5 as an example below if subtracting 5 from 50, the desired result is;
50 45 40 35 30
50 0 0 0 0
50 45 40 35 30
Instead I'm getting;
50 45 45 45 45
50 0 0 0 0
50 45 45 45 45
My for loop takes the shape;
for i=[1:a-1]
Where T = 50 and td = 8.333 (not that I imagine they are relevant to you mega minds).
So what I need is to know where I am going wrong (assuming the T-td is at fault somehow) and best way to fix it please?
I will just add that this is part of an assignment I have on but by you providing me with assistance, you are not aiding a cheat. I am perfectly compliant within rules and regs for seeking knowledge from more experienced and reliable sources. Getting to see my lecturer can be tricky (lecture times/ school pick-ups etc) so just trying to save time by coming on here.
I have looked on several pages here and on 'help' at the campus but I'm as much use as a chocolate fireguard sometimes and now is one of them times... Can't find what I need (or it's just not making sense).
I am not totally sure what version MatLab is on the campus systems either (chocolate fireguard?), think they appear to vary from stacks that were connected to the network but no longer are and stacks that are connected to a network so may range from 2010-2014 (possibly).
I thank you in advance for any help you may provide. Also, would you offer a brief description to better my understanding (really struggle with for loops, just like I have with differentiation for years - enjoy basic matrices and integration though (strange boy!)).
Leighton on 18 Nov 2014
Edited: Leighton on 18 Nov 2014
Nevermind, I've sussed it.
For anyone interested, i found this sorted it;
for i=[1:a-1]
for j=i+1;
Just needs an if statement to deal with negligible but potential negative decimals.

Sign in to comment.

Answers (1)

MA on 18 Nov 2014
clear all
close all
for i=1:a-1

Community Treasure Hunt

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

Start Hunting!