how to handle unknown size of arrey
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Actually i am going to use structural data that is very large and i have to use it one by one and i do not know what is its size. so please help me how can i handle it.
3 Comments
Rik
on 3 Feb 2020
What do you mean with 'handle'? What is your input and what is your intended output?
Chaudhary P Patel
on 3 Feb 2020
Answers (1)
Star Strider
on 2 Feb 2020
Use the size function to get the dimensions. There are other functions in and at the end of the size documentation that can provide you with similar results.
To use the results, assuming ‘A’ is your array, to index the the rows:
r_idx = 1:size(A,1);
and the columns:
c_idx = 1:size(A,2);
and other dimensions as necessary.
21 Comments
Chaudhary P Patel
on 3 Feb 2020
Walter Roberson
on 3 Feb 2020
NEL = numel(YourStructure);
Output = cell(size(YourStructure));
for Lidx = 1 : NEL
this_entry = YourStructure(Lidx);
now calculate based on this_entry.AppropriateField
Output{Lidx} = calculated result;
end
The result, Output, will be a cell array the same size as YourStructure.
Chaudhary P Patel
on 3 Feb 2020
Walter Roberson
on 3 Feb 2020
acceleration_cell = {YourStructure.NameOfTheAccelarationDataField};
N = ndims(acceleration_cell{1});
acceleration_array = cat(N+1, acceleration_cell{:});
Now if all went well, acceleration_array will be an array with one more dimension than the individual acceleration data. For example if the acceleration data struct fields are 2D then acceleration_array will be 3D, with the third dimension reflecting the linear index into the structure array.
This relies upon the various structure array entries all being the same size. If that is not the case, then you need to tell us how you want the data to be put together into a numeric array.
Chaudhary P Patel
on 3 Feb 2020
Walter Roberson
on 3 Feb 2020
readtable() the file, possibly using a Range option to indicate a group of adjacent columns to read.
Chaudhary P Patel
on 3 Feb 2020
Walter Roberson
on 3 Feb 2020
Did you readtable or did you xlsread or did you importdata?
Chaudhary P Patel
on 3 Feb 2020
Star Strider
on 3 Feb 2020
I do not understand the problem. Both columns are vectors, and the two together form a matrix.
Please describe in more detail what you want to do.
Chaudhary P Patel
on 3 Feb 2020
Star Strider
on 3 Feb 2020
I still do not understand.
Perhaps:
Time = (0:0.005:0.055)'; % Create Vector (Original Not Provided)
Acc = -rand(size(Time)); % Create Vector (Original Not Provided)
A = table(Time,Acc)
C = table((1:size(A,1))', 'VariableNAmes',{'C'}); % Row Numbers
A = [C, A]
producing:
A =
12×3 table
C Time Acc
__ _____ ________
1 0 -0.84193
2 0.005 -0.83292
3 0.01 -0.25644
4 0.015 -0.61346
5 0.02 -0.58225
6 0.025 -0.54074
7 0.03 -0.86994
8 0.035 -0.26478
9 0.04 -0.31807
10 0.045 -0.11921
11 0.05 -0.93983
12 0.055 -0.64555
Chaudhary P Patel
on 3 Feb 2020
Star Strider
on 3 Feb 2020
This was just an example, since I have no idea what you want.
Is that close to what you want, or do you want something else?
Chaudhary P Patel
on 3 Feb 2020
Chaudhary P Patel
on 3 Feb 2020
Chaudhary P Patel
on 3 Feb 2020
Star Strider
on 3 Feb 2020
I am still lost. My background is in electrical engineering, not structural engineering, so none of this is intuitive to me.
I have absolutely no idea what you want to do with the vector and mass multiplication. Is the mass a scalar, vector, or matrix? What are the sizes of each?
Chaudhary P Patel
on 3 Feb 2020
Star Strider
on 3 Feb 2020
As I mentioned, this has gotten from something I am comfortable working with (general MATLAB coding in this instance) to structural engineering that is beyond my expertise.
I am stopping here, intending that someone with relevant expertise continue it.
You will likely need to use a loop to multiply your (8x8) mass matrix by individual single elements of your acceleration vector. What you then do with the result, I have absolutely no idea.
Beyond that, please do not use the eval function! There are much better and more efficient ways of doing what you want.
Walter Roberson
on 3 Feb 2020
Do not use importdata. Use readtable
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!