Create a Vector Field from a Cell Array

5 views (last 30 days)
Carl
Carl on 5 Apr 2013
I am attempting to create a vector field from a cell array of stored vectors. However I am having some difficulty getting the vectors out of the cell array and graphed. I was wondering if anyone could tell me if there was a way to get the stored vectors from the cell array and plotted as a vector field besides typing each individual element in separately. Thank you for any help.
clear all;
clc
A = [-3, -2; 5, -1];
for i = 1:12
X_t{i} = [A*[i-1;i]];
X_t{i+1} = [A*[i;i-1]];
X_t{i+2} = [A*[i;i]];
end
figure
hold on
quiver(X_t{1}, X_t{2})
hold off
  1 Comment
Jan
Jan on 5 Apr 2013
Beside other unwanted stuff, "clear all" clears all breakpoints in the code. It is such a bad idea to prevent debugging conceptionally, that I can and must suggest to avoid this brute clearing.
Wat is a "vector field" here exactly? What does "I'm having some difficulties" exactly mean?

Sign in to comment.

Answers (1)

Jan
Jan on 5 Apr 2013
Edited: Jan on 5 Apr 2013
As long as you do not explain, what the code should achieve, I cannot suggest an improvement.
for i = 1:12
X_t{i} = [A*[i-1;i]];
X_t{i+1} = [A*[i;i-1]];
X_t{i+2} = [A*[i;i]];
end
You can omit the outer square brackets, as MLint most likely suggests already. Then in the first iteration you create the cell elements X{1}, X{2} and X{3}. In the 2nd iteration for i=2, you overwrite X{2} and X{3}, while X{4} is created. Therefore most elements of the cell vector X are overwritten several times and this is not useful. I cannot guess what you want to achieve instead.
Without the brute clearing header, you had a chance to use the debugger by setting a breakpoint. Then steppoing through the code would easily reveal, what's going on inside.
The documentation of quiver (type "doc quiver" in the command window) does not mention any cell arrays. The examples shown there do not use cell arrays also. So why do you want to choose this type to represent your data? Some matrices are more efficient and easier.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!