creating a matrix from different sized arrays

2 次查看(过去 30 天)
Hello,
i have some test data to analyse, the data is in arrays of varying size but the names of the arrays are all similar eg; mmXXXgX (where X are numbers relating to a specific test situation)
Basically everything is taking ages to do because i can't seam to make a matrix out of it, i also don't want to cut down any of them as the amount of data varies significantly from one to the next. i was thinking about extending them with 0s but i was worried it would mess up the results if it tried to Fourier transform them.
The latest thing i have been trying involves a matrix of their names as text strings but this doesn't seem to work either.
I have never used this forum before so please let me know if i have missed anything out.
this is the code from the last attempt (it was a bit hopeful i didn't really expect it to work):
a=['mm100g0','mm155g0','mm195g0','mm215g0','mm235g0','mm295g0'
'mm100g1','mm155g1','mm195g1','mm215g1','mm235g1','mm295g1'];
peakv=zeros(size(a));
for r=1:2
for c=1:6
peakv(r,c)=fd(a(r,c));
end
end
fd() is just a function that returns a single value (the peak voltage)
Any help would be greatly appreciated, thank you
Michael

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-5-15
x = [100 155 195 215 235 295];
y = 0:1;
[ii jj] = ndgrid(y,x);
a = eval(['reshape({',sprintf('mm%dg%d,',[jj(:),ii(:)]'),'},size(jj))']);
or:
a={mm100g0,mm155g0,mm195g0,mm215g0,mm235g0,mm295g0;mm100g1,mm155g1,mm195g1,mm215g1,mm235g1,mm295g1}
% example of use
peakv = cellfun(@fd,a);

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2012-5-15
This should get you started, ask us for any clarifications.

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by