Info

This question is closed. Reopen it to edit or answer.

How do I calculate equation sets of 3 unknown x,y,z given csv. file with 30 different sets of equations?

1 view (last 30 days)
Hi I'm fairly new to Matlab and I'm having issues figuring out how to solve this problem: Given a csv. file with 90 rows of values (ex. -38,-16,40,-19), each representing a part of an equation set of 3 (that means 3x30 sets of equations). I'm asked to return the equations in the first output of the function, and the following answer in the second output. Is there a fast, neat way to solve this? Please help
  1 Comment
John D'Errico
John D'Errico on 6 Oct 2016
Just use a loop. Fast. Efficient. Simple to write. There is no reason to need to make this vectorized. Sometimes people want to see a nice expression that magically does what you want. But too often that one line expression is impossible to read. It works, but why bother here?

Answers (1)

Hoai Tran Quoc
Hoai Tran Quoc on 7 Oct 2016
Hope it helps you.
a = csvread('testEQdata.csv');
X = zeros(90,1);
for i = 1:30
A = a((i-1)*3+1:(i-1)*3+3,1:3);
B = a((i-1)*3+1:(i-1)*3+3,4);
X((i-1)*3+1:(i-1)*3+3,1) = linsolve(A,B);
end
disp(X);

Community Treasure Hunt

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

Start Hunting!