how to plot contour ?
1 view (last 30 days)
Show older comments
How to do the below mentioned process in the loop and save contour. Please share your knowledge. Attached data for your reference.
I tried to create a loop but got the Error: Invalid array indexing. T = readtable('HB2B_2530.csv','PreserveVariableNames',true); Vx = table2array(T(:,:));%X TTT = Vx(:,10:13); A=unique(TTT,'rows'); Acell=splitapply(@(x){x}, A,findgroups(A(:,2))); Acell{:}; y1 = [Acell{1,:}];%first plane values y2 = [Acell{2,:}];%second plane values y3 = [Acell{3,:}];%third plane values y4 = [Acell{4,:}];%fourth plane values for i= 1:4 rg(i) = linspace(min(y(i)(:,1)), max(y(i)(:,1)), 100); cg(i) = linspace(min(y(i)(:,3)), max(y(i)(:,3)), 100); [Rg(i), Cg(i)] = meshgrid(rg(i), cg(i)); Zg(i) = griddata(y(i)(:,1), y(i)(:,3), y(i)(:,4), Rg(i), Cg(i)); contourf(Rg(i),Cg(i),Zg(i)); end
2 Comments
Walter Roberson
on 16 Dec 2022
I am not sure what you mean by "save contour in auto" ?
Acell{:};
What is the purpose of that line?
Is there a reason you are using readtable() followed by table2array() instead of using readmatrix() ?
Accepted Answer
Walter Roberson
on 16 Dec 2022
T = readtable('HB2B_2530.csv','PreserveVariableNames',true);
Vx = table2array(T(:,:));%X
TTT = Vx(:,10:13);
A = unique(TTT,'rows');
Acell = splitapply(@(x){x}, A,findgroups(A(:,2)));
Acell{:};
y1 = [Acell{1,:}];%first plane values
y2 = [Acell{2,:}];%second plane values
y3 = [Acell{3,:}];%third plane values
y4 = [Acell{4,:}];%fourth plane values
y = {y1, y2, y3, y4};
N = length(y);
rg = cell(N,1); cg = cell(N,1);
Rg = cell(N,1); Cg = cell(N,1);
Zg = cell(N,1);
for i= 1:N
rg{i} = linspace(min(y{i}(:,1)), max(y{i}(:,1)), 100);
cg{i} = linspace(min(y{i}(:,3)), max(y{i}(:,3)), 100);
[Rg{i}, Cg{i}] = meshgrid(rg{i}, cg{i});
Zg{i} = griddata(y{i}(:,1), y{i}(:,3), y{i}(:,4), Rg{i}, Cg{i});
subplot(N,1,i);
contourf(Rg{i}, Cg{i}, Zg{i});
end
Acell will be a cell array in which each matrix is a composed of rows extracted from the array A that has four columns. It will have as many entries as there are distinct groups in the data. The code assumes that there are at least 4 such groups. Acell will have as many columns as findgrous(A(:,2)) has, which would be 1, so Acell will be som
So Acell{1,:} would be the same as Acell{1,1} since Acell will be something x 1. Since there is only one cell being accessed, the result of [Acell{1,1}] would be the same as if you had used Acell{1} directly .
Now suppose that somehow you had Acell being an N x 2 cell array such that Acell{1,:} would be different than Acell{1} . In such a case [Acell{1,:}] would be [Acell{1,1}, Acell{1,2}] which would be expecting to be able to horizontally concatenate those two arrays. But do we know if those (hypothetical) arrays are even the same height to be able to [] them together ? If these hypothetical arrays are, hypothetically, the same height then the result of the [] would have more than 4 columns, but your code processing y ignores anything past the 4th column... so why bother to [] the (hypothetical) rows together?
7 Comments
Walter Roberson
on 19 Dec 2022
It is not obvious to me that edges are missing, since you did set the line color to none
More Answers (0)
See Also
Categories
Find more on Colormaps 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!