extract values from specific cells in excel

Hi, I would like to values from specific cells in excel file>>>>>>. Please help me with script to do that. for example, I would like to copy values from cells A1, A6, A11,..A1501....and cells B1, B6, B11,.....B1501 ( as shown in the attached file) into another excel file format. Please note that the reoccurence could be more than the 5 cells in this example. That is it could be A1, A11, A21 (10 cells jump)...or A1, A33, A65,..(32 cells jump) etc. but in all cases reoccurence is always constant.
Thanks for helping

 채택된 답변

Caroline
Caroline 2013년 8월 1일

2 개 추천

You can use xlsread:
For example: num = xlsread(filename,sheet,xlRange) and you can specify xlRange to be whatever columns you want to read and it will save all of the values in the cell array num. Then you could possibly index into that cell array and get the values that you need and save those values in a new array.
The you can use xlswrite:
xlswrite(filename,A,sheet,xlRange)
where A would be the array that you created

댓글 수: 4

olu
olu 2013년 8월 1일
Thanks for your answer Caroline. I am not good with indexing which is the challenge I am facing. i was able to write the script below which can only call the first A-B pair. I know I need to index so that values at regular intervals can be got as well. Any more advice would be appreciated. Thanks
filename='Book.xls' A=xlsread(filename); sheet = 1 xlRang='B1:B1'; xlRange='A1:A1'; T=xlsread(filename,sheet,xlRang); Y=xlsread(filename,sheet,xlRange); d=[T Y]; xlswrite('Called', d);
To read the excel file and get the values that you want I think I would do something like this:
num1 = xlsread('C:\path_to_filename', 'A:A'); %read in first column
num2 = xlsread('C:\path_to_filename', 'B:B'); %read in second column
len= length(num1);
%length of num1 and num2,assuming there are the same number of values in columns A and B
num1_new = zeros; %creates array of all zeros num2_new = zeros; %creates array of all zeros
ind = 0; %will use this as an index into new array with the extracted values
%if for example you want to get the 1st, 3rd, 5th...
for i= 1:2:len
%go from 1 to length of n in increments of 2 (the step would change depending on which values you want to extract)
ind = ind + 1;
num1_new(ind) = num1(i);
num2_new(ind) = num2(i);
end
num1_new would contain all of the relevant values from column A, and num2_new would contain all of the relevant values from column B
olu
olu 2013년 8월 1일
Hi Caroline, thanks so much for this. It has helped me solve my problem. You are a life saver.
cheers
C G
C G 2018년 4월 5일
How do I combine the values from columns A and B? For example, I would like a new variable with the values from A1 and B1 in the same variable? Then have a new variable containing the values of A2 and B2 in the new variable... and so on.

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

추가 답변 (1개)

Prakash Adhikari
Prakash Adhikari 2020년 9월 15일
편집: Prakash Adhikari 2020년 9월 15일

0 개 추천

How do I find the row and column number of a specific data of excel file in matlab?

댓글 수: 1

Carlos GU
Carlos GU 2022년 7월 30일
편집: Carlos GU 2022년 7월 30일
Hi
you can xlsread the file and then use 'find' to get row and column number as below script:
File=xlsread(filename);
[rowlist, collist]=find(File=='specific data');
If you want to get the column letters instead of column number, below link may help you:

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

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

질문:

olu
2013년 8월 1일

편집:

2022년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by