ploting data from the rearranged data in excel

조회 수: 1 (최근 30일)
S
S 2014년 1월 31일
댓글: S 2014년 1월 31일
Hi all, I have been working on my problem for days and days, and I just can not fix it.
I have my data in the attached excel file, I am stock by transferring the data. For the plot, I want X as A4:A43. matrix 'data' has been defined to collect the data.I just add these code to explain how I want the data stored in 'data'.
data=zeros(40,40);
X=xlsread('F:\RA\Parallel\Parallel.xls','Data','A4:A43');
Y=(1:40)';
%adder=39;
data(:,1)=xlsread('F:\Parallel\Parallel.xls','Data','C4:C43');
data(:,2)=xlsread('F:\Parallel\Parallel.xls','Data','C44:C83');
data(:,3)=xlsread('F:\Parallel\Parallel.xls','Data','C84:C123');
data(:,4)=xlsread('F:\Parallel\Parallel.xls','Data','C124:C163');
data(:,5)=xlsread('F:\Parallel\Parallel.xls','Data','C164:C203');
data(:,6)=xlsread('F:\Parallel\Parallel.xls','Data','C204:C243');
data(:,7)=xlsread('F:\Parallel\Parallel.xls','Data','C244:C283');
data(:,8)=xlsread('F:\Parallel\Parallel.xls','Data','C284:C323');
data(:,9)=xlsread('F:\Parallel\Parallel.xls','Data','C324:C363');
data(:,10)=xlsread('F:\Parallel\Parallel.xls','Data','C364:C403');
.
.
.
data(:,37)=xlsread('F:\Parallel\Parallel.xls','Data','C1444:C1483');
data(:,38)=xlsread('F:\Parallel\Parallel.xls','Data','C1484:C1523');
data(:,39)=xlsread('F:\Parallel\Parallel.xls','Data','C1524:C1563');
data(:,40)=xlsread('F:\Parallel\Parallel.xls','Data','C1564:C1603');
I want to do it in loops for later on if I add more data, but I cant make it right!!These are my new codes:
clear all
clc
format bank
data=zeros(40,40);
X=xlsread('F:\RA\Parallel\Parallel.xls','Data','A4:A43');
Y=(1:40)';
% adder=39;
% cc1=4;
% cc2=43;
for r=1:40
for c=1:40
for counter=4:43
data(c,r)=xlsread('F:\RA\Parallel\Parallel.xls','Data',['C' num2str(counter)]);
c=c+1;
end
r=r+1;
counter=counter+1;
end
colormap(hsv(16));
%colormap(hot(256));
%figure,surf(X,Y,data,'FaceColor','EdgeColor','FaceLighting');
surf(X,Y,data,'FaceColor','interp','FaceLighting','phong');
set(gca,'ZDir','reverse');
view(0,90);axis([0 15.8 1 40 -inf inf])
camlight right;
lighting phong;
%colorbar;
shading interp
end
I appreciate your help. Thank you.
Regards, S :-)
  댓글 수: 2
dpb
dpb 2014년 1월 31일
More useful would be what is the actual problem you're running into and any error messages, etc., on specific line(s) of code.
S
S 2014년 1월 31일
Thanks for your reply and comment. I'll try to apply it.

댓글을 달려면 로그인하십시오.

채택된 답변

Mischa Kim
Mischa Kim 2014년 1월 31일
편집: Mischa Kim 2014년 1월 31일
  • First, don't increment loop indices (e.g. c). This is done automatically.
  • In the inner loop you keep overwriting data(c,r) with new data.
  • Lastly, why don't you use just one loop where you write to data(:,ii) (I am just using ii as my running loop index) like you have shown in your code all the way on the top?
  댓글 수: 3
Mischa Kim
Mischa Kim 2014년 1월 31일
편집: Mischa Kim 2014년 1월 31일
Something like:
...
for ii = 1:40
low_ind = 4 + 40*(ii - 1);
high_ind = low_ind + 39;
table_ind = strcat('C', num2str(low_ind), ':C', num2str(high_ind));
data(:,ii) = xlsread('F:\Parallel\Parallel.xls','Data',table_ind);
end
...
S
S 2014년 1월 31일
That's it. Thanks.Instead of having the following line:
table_ind = strcat('C', num2str(low_ind), ':C', num2str(high_ind));
I was trying
xlsread('F:\Parallel\Parallel.xls','Data',['C', num2str(low_ind), :'C', num2str(high_ind)]
It did not work. I'll try the rest myself. Thank you again. I learned a new command :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by