How can I use the value of one index in a structured element as the index in a logical statement?

1 visualización (últimos 30 días)
Hello,
I have a set of data within a structured element, with each "label" if you will in the first column, and the data that goes with that in the same row. I'm trying to use the data values within each field as an index to another array in a for loop.
I have several large sets of data of which almost all are indicated by "PointID", and then several "PointID" make up a segment, "SegID". I want to gather data about each individual segment, so I must gather data using the corresponding Point ID.
The following is the code I'm working with--I'm sure it could be more efficient, but not what I need help on :) I'm having trouble in the last for loop, specifically the if statement. I'm getting the error: Matrix dimensions must agree. Error in ExcelConvert (line 37) if PointID{n,2}==ThickPoint; I think it's because I'm working with the structure--the total number of points are the same, but in the structure they are grouped into fields. Attachted is a screen shot of workspace.
Thanks in advance for any direction!
clear
clc
a=importdata('Segments.xlsx');
b=importdata('Points.xlsx');
%% Excel to Array for Points Sheet
PointPoint=b.data(:,1);
Thick=b.data(:,2);
XCoor=b.data(:,3);
YCoor=b.data(:,4);
ZCoor=b.data(:,5);
%% Excel to Array for Segments Sheet
SegID=a.data(:,1);
CurvL=a.data(:,2);
D=a.data(:,3);
A=a.data(:,4);
V=a.data(:,5);
CrossA=a.data(:,6);
CrossPer=a.data(:,7);
i=43977;
PointID = cell(i,1);
for i=2:43977;
PointID{i-1,1}=i-1;
PointID{i-1,2}=transpose(a.data(i,10:end));
end
%% Correspond Segment Point Columns (PointID) with Thickness Rows (Take PointIDS within Structure for each segment, use that # as an indice on getting data from the thickness and append to a new table)
ThickSeg=cell(i,1)
ThickPoint=[PointPoint,Thick];
for n=1:43977
if PointID{n,2}==ThickPoint;
A=PointID{n,1};
ThickSeg=ThickPoint(A,2);
end
end

Respuestas (1)

Kavya Vuriti
Kavya Vuriti el 15 de Nov. de 2019
Editada: Kavya Vuriti el 15 de Nov. de 2019
Hi,
I would like to assume dimensions of data field in structure ‘a’ as 43977 x 20 for easy understanding. According to the code provided and assumption made, PointID{n, 2} will be of dimensions 11 x 1 and ThickPoint is of dimensions 358440 x 2. There is mismatch of dimensions during array comparison using ‘==’ which leads to the error message mentioned. Try to make sure that the arrays being compared are of same dimensions.
Hope this helps.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by