Suppose, one of the my columns in my excel data as follows:
'G1(f1) : Resulting Value = 0.5'
'G1(f2) : Resulting Value = 1'
'G1(f3) : Resulting Value = 1.5'
'G1(f4) : Resulting Value = 2'
.
.
.
'G1(f8) : Resulting Value = 4'
I'd like to separate the values that 0.5, 1 ... 4 as double!
I have tried the code below:
plotdata=xlsread('S:/PLOT/PLOT.xlsx');
[num, txt] = xlsread('S:/PLOT/PLOT.xlsx', 'B4:B43');
[rows,cols]=size(txt);
uplim=plotdata(2,2); %this cell gives number of 'Resulting Value's
k=1;
for i=4:uplim+4-1
[dummy(k), txt(k)] = strtok(txt(k), '=');
mylist(k)=strtok(txt(k),'= ');
k=k+1;
i=i+1;
end
This code gives "mylist" as 1x8 cell!
THE PROBLEM is that I can not use "mylist" for arithmetic operations. How can I turn "mylist" from cell to a matrix or a vector that I can use for arithmetic operations.
Or I'm open to new codes to separate the values that 0.5, 1 ... 4 as double!

댓글 수: 5

Try
mylist = [mylist{:}]
What you are doing can actually be achieved in a simpler way. Can you attach your file?
Nope. It gives
mylist =
0.511.522.533.54
ugur uresin
ugur uresin 2018년 7월 1일
Dear Paolo, Mydata file has been attached!
Paolo
Paolo 2018년 7월 1일
Of course, my bad. Conversion from char to double is necessary. Please check my answer below. By the way, in the file you attached, data ranges from B4 to B11.
ugur uresin
ugur uresin 2018년 7월 1일
편집: ugur uresin 2018년 7월 1일
It always starts from B4 and ends to B"x"
x: Number of functions in my data and it's given in B2

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

 채택된 답변

Paolo
Paolo 2018년 7월 1일
편집: Paolo 2018년 7월 1일

0 개 추천

[num, txt] = xlsread('mydata.xlsx', 'B4:B11');
mylist = cellfun(@(x) str2double(regexp(x,'(\d*\.?\d*)$','match')),txt);

댓글 수: 2

ugur uresin
ugur uresin 2018년 7월 1일
It works! Thanks a lot Sir.
You are welcome. You may also use:
[num, txt] = xlsread('mydata.xlsx', 'B4:B11');
[~,mylist] =strtok(txt,'=');
mylist =str2double(strtok(mylist,'='));

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

추가 답변 (1개)

Jan
Jan 2018년 7월 1일
편집: Jan 2018년 7월 1일

0 개 추천

Remember, that txt is a cell array. Then eitehr use
[dummy, str] = strtok(txt{k}, '=');
But strtok can operate on the complete cell also:
[~, mylist] = strtok(txt(4:uplim+4-1), '=');
mylist = strrep(mylist('= ', ''));
Note: i=i+1; is confusing but useless only inside a for i loop.

댓글 수: 2

It gives an error
Index exceeds matrix dimensions.
Jan
Jan 2018년 7월 1일
Then adjust the index: 4:uplim+4-1 to 1:uplim.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2018년 7월 1일

댓글:

Jan
2018년 7월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by