MATLAB Answers

# Writing multiple structures to user specified excel file

4 views (last 30 days)
Ibro Tutic on 5 Apr 2016
Commented: Ibro Tutic on 5 Apr 2016
I have a variable amount of structures with 4 fields, each containing 1x1 blocks of data. How would I go about writing multiple structures to a user specified excel file?

#### 2 Comments

Azzi Abdelmalek on 5 Apr 2016
Can you give an example?
Ibro Tutic on 5 Apr 2016
Sure, they look like this, in general.

Sign in to comment.

### Accepted Answer

Azzi Abdelmalek on 5 Apr 2016
Edited: Azzi Abdelmalek on 5 Apr 2016
load Example
v=[struct2cell(Data1.data)]
out=v(:,:)'
xlswrite('file.xlsx',out)

#### 18 Comments

Ibro Tutic on 5 Apr 2016
filepath1 = 'C:\Users\it58528\Desktop\13.5 Stuff\13.5 Mat Files\';
filename = uigetfile('*.*', 'All Files (*.*)','MultiSelect','on');
for n=1:length(filename)
data1{n} = load([filepath1 filename{n}]);
end
for i=1:length(data1)
for j=1:length(data1{i}.PIN)
Data(i).data(j).PIN = data1{i}.PIN(j).PIN;
Data(i).data(j).hours = data1{i}.PIN(j).hours;
Data(i).data(j).Disp = data1{i}.PIN(j).Displacement;
Data(i).data(j).damage = sum(sum((data1{i}.PIN(j).LoadProfilePercent.*DamagenewTable),1));
end
end
for i=1:length(data1)
v=[struct2cell(Data(i).data)];
out=[v(:,:)'];
end
Azzi Abdelmalek on 5 Apr 2016
You did not look at my code!
out=[]
for i=1:length(data1)
v=[struct2cell(Data(i).data)];
out=[out;v(:,:)'];
end
Ibro Tutic on 5 Apr 2016
Oh that worked! Thank you!

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!

Translated by