plotting separate parts of a column on different figures
6 次查看(过去 30 天)
显示 更早的评论
I have a large matrix. In the 3rd column, I have my "eta" values. In my 4th column, I have "r" values. In my 8th column, I have "g" values.
Eta is the same as you go down column for a while. How can I plot g vs. r as long as eta is the same, then make a new plot with g vs r anytime eta changes?
Maybe the matrix needs to be reshaped first? Note that the number of eta values that are the same can change.
6 个评论
Stephen23
2019-3-27
编辑:Stephen23
2019-3-27
"But all of them are different sizes though, they can't easily go into an array"
That is exactly what cell arrays are for.
"The alternative is I just import the sheet name "Master" and then I have all the data."
That would likely be the best solution.
"Then I have the problem that I initially asked in this question. By loading them in separately, I don't have to separate them in MATLAB."
Processing the data within MATLAB is much more efficient than importing data from file multiple times (hard-drives are very slow!). Simply import that data all at once, use diff to detect where eta changes, then loop over those indices and plot the data.
采纳的回答
Stephen23
2019-3-27
编辑:Stephen23
2019-3-27
Following your description "I have a large matrix. In the 3rd column, I have my "eta" values. In my 4th column, I have "r" values. In my 8th column, I have "g" values", here is one simple loop:
% Random fake data with contiguous eta groups:
mat = rand(32,8);
mat(:,3) = sort(randi(9,32,1));
% Detect eta groups (i.e. changes in eta):
bnd = find([true;diff(mat(:,3));true]);
% Plot data for each eta group:
for k = 1:numel(bnd)-1
figure() % using ONE figure is usually simpler.
idx = bnd(k):bnd(k+1)-1;
G = mat(idx,8);
R = mat(idx,4);
plot(R,G) % or plot(G,R), whatever you want
title(sprintf('eta = %d',mat(bnd(k),3)))
end
8 个评论
Stephen23
2019-3-28
编辑:Stephen23
2019-3-28
"The number of R values changes on each eta value."
It is not clear to me what this means.
"Is there a way to circumvent this?"
As far a I can tell you could use the dimensions of your arrays. For example, if R is a column vector and eta a row vector, then they can be different lengths and you wll get all values at the output:
>> eta = [1,2,3]; % row
>> R = [4;5;6;7]; % column
>> R.^eta
ans =
4 16 64
5 25 125
6 36 216
7 49 343
Use higher dimensions if required: e.g. if R is an MxN matrix that you do not want to reshape, then reshape eta to a 1x1xP vector, it works in exactly the same way.
Using the dimensions ot arrays is one of MATLAB's most powerful features.
For MATLAB versions prior to R2016b you will need to use bsxfun.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!