Info
This question is closed. Reopen it to edit or answer.
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how to handle unknown size of arrey
1 view (last 30 days)
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
Chaudhary P Patel
on 3 Feb 2020
sir i have a acceleration data for a dynamic struture which i have to create an array form for the further analysis.
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
but here i am not interested to konw the size of the data. my concern is, how can i handle it and write as an array form.
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
sir i have a acceleration data for a dynamic struture which i have to create an array form for the further analysis.
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
i have data in axcel form and acceleration in one column and unknown size of row then how will be it work.
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
acce_cell = {acce(:,2)}; %% it was reading data from excel
q = ndims(acce_cell{1});
acce_array = cat(q+1, acce_cell{:});
but it is not working.
Walter Roberson
on 3 Feb 2020
Did you readtable or did you xlsread or did you importdata?
Chaudhary P Patel
on 3 Feb 2020
importdata.
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
i want to form a array of second column which have unknown nymbers of rows with a cloumn.
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
the time is very large and the acceleration changes from negative to positive also.
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
ok sir, i am telling you in details. actually i am working with some structural dynamics model for the evaluation of load due the acceleration from the dynamics data which is very large. for load evaluation i have to multiply this acceleration with global elemental maas so i want the acceleration data in array form.
Chaudhary P Patel
on 3 Feb 2020
hope you understand now!!
Chaudhary P Patel
on 3 Feb 2020
anothe point i am giving you sir, see i have a vecto size is (m by 1) where m is unkown now i want to create it i an array form.
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
mass is a matrix of ( 8 by 8) and i have to multiply acceleration with it for every single acceleration. when i am multiplying with single value than its ok but i use a loop for like
for j=1:1:Ug %% this is acceleration coming from excel
for i=1:ne %%% number of element
Ecc=eval(['Ee',num2str(i)]);
acc=[0.3*Ug(j,1);Ug(j,1);0;Ecc.*(Ug(j,1))';0.3*Ug(j,1);Ug(j,1);0;Ecc.*(Ug(j,1))'];
mas = eval(['m',num2str(i)]); %% calling global elemental mass matrix
eval(['force',num2str(i),'=mas*acc']);
end
end
this is not working with all value in a loop.
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
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)