Info
此问题已关闭。 请重新打开它进行编辑或回答。
how to handle unknown size of arrey
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Chaudhary P Patel
2020-2-3
sir i have a acceleration data for a dynamic struture which i have to create an array form for the further analysis.
Rik
2020-2-3
此问题已关闭。
回答(1 个)
Star Strider
2020-2-2
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 个评论
Chaudhary P Patel
2020-2-3
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
2020-2-3
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
2020-2-3
sir i have a acceleration data for a dynamic struture which i have to create an array form for the further analysis.
Walter Roberson
2020-2-3
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
2020-2-3
i have data in axcel form and acceleration in one column and unknown size of row then how will be it work.
Walter Roberson
2020-2-3
readtable() the file, possibly using a Range option to indicate a group of adjacent columns to read.
Chaudhary P Patel
2020-2-3
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.
Star Strider
2020-2-3
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
2020-2-3
i want to form a array of second column which have unknown nymbers of rows with a cloumn.
Star Strider
2020-2-3
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
2020-2-3
the time is very large and the acceleration changes from negative to positive also.
Star Strider
2020-2-3
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
2020-2-3
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
2020-2-3
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
2020-2-3
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
2020-2-3
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
2020-2-3
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.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)