Dimensions of matrices being concatenated are not consistent.

fid=fopen('Data2.txt'); %will read notepad data
s=textscan(fid,'%f %f','headerlines',2); %variable "s" will show and plot data
g = cell2mat(s); %i have error here
x=g(:,1);
y=g(:,2);
[sortedX, sortIndex] = sort(x);
sortedY = y(sortIndex);
findpeaks(sortedYLimited,sortedXLimited,'MinPeakProminence',205,'Annotate','extents')
[psor,lsor] = findpeaks(sortedYLimited,sortedXLimited,'MinPeakProminence',205,'SortStr','descend')
i have this code but it doesnt work im trying to graph these data:
Data2.txt <-- this is notepad
5.000, 26.000
5.010, 28.000
5.020, 28.000
5.030, 39.000
5.040, 28.000
5.050, 37.000
5.060, 30.000

7 件のコメント

Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 17 日
May i know what is inconsistent here. Which variables are you trying to concatenate? what is Data2.txt?
sydney salvador
sydney salvador 2020 年 3 月 17 日
matlab says that cell2 mat causes an error and Data2.txt is my data that i Am trying to plot which is
5.000, 26.000
5.010, 28.000
5.020, 28.000
5.030, 39.000
5.040, 28.000
5.050, 37.000
5.060, 30.000
sydney salvador
sydney salvador 2020 年 3 月 17 日
i would think i am trying to concatenate variable "s"
Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 17 日
Can you confirm if s is a cell? if yes, What are different dimensions in each cell?
sydney salvador
sydney salvador 2020 年 3 月 17 日
yes, yes, i am sorry, i have not explained it carefully, the recorded numbers are text based outside of the program and could only be read by textscan, I thought i understand that the recorded numbers can be a cell after that, because i use another data sheet on where the data has no decimal places and it was graphed by matlab
sydney salvador
sydney salvador 2020 年 3 月 17 日
it might not be a cell, because it can be seen as a big table of 100 rows and 2 columns
Guillaume
Guillaume 2020 年 3 月 17 日
Attaching the input file to the question would greatly help in understanding the problem.
What version of matlab are you on that you're still using texscan when a one-line readmatrix would probably import your file directly as a matrix.
g = readmatrix('Data2.txt'); %A much more meaningfull variable name than g would be a very good idea!

サインインしてコメントする。

回答 (1 件)

Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 17 日

0 投票

Hi,
I see that the issue is with usage of textscan function. Replace the line with this
s=textscan(fid,'%f, %f','headerlines',2); %variable "s" will show and plot data
For more details about usage of this function, go through https://www.mathworks.com/help/matlab/ref/textscan.html#btghhyz-5
Hope this helps.
Regards,
Sriram

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

質問済み:

2020 年 3 月 17 日

コメント済み:

2020 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by